unit iocp.WinHttp;

interface

uses
  Windows, iocp.Winapi.WinSock;

{ Crypto functions needed }
type
  HCRYPTPROV = ULONG_PTR;
  {$EXTERNALSYM HCRYPTPROV}

  _CRYPTOAPI_BLOB = record
    cbData: DWORD;
    pbData: LPBYTE;
  end;
  {$EXTERNALSYM _CRYPTOAPI_BLOB}
  CRYPT_INTEGER_BLOB = _CRYPTOAPI_BLOB;
  {$EXTERNALSYM CRYPT_INTEGER_BLOB}
  PCRYPT_INTEGER_BLOB = ^_CRYPTOAPI_BLOB;
  {$EXTERNALSYM PCRYPT_INTEGER_BLOB}
  CRYPT_OBJID_BLOB = _CRYPTOAPI_BLOB;
  {$EXTERNALSYM CRYPT_OBJID_BLOB}
  CERT_NAME_BLOB = _CRYPTOAPI_BLOB;
  {$EXTERNALSYM CERT_NAME_BLOB}
  PCERT_NAME_BLOB = ^CERT_NAME_BLOB;
  {$EXTERNALSYM PCERT_NAME_BLOB}

  PCRYPT_BIT_BLOB = ^CRYPT_BIT_BLOB;
  {$EXTERNALSYM PCRYPT_BIT_BLOB}
  _CRYPT_BIT_BLOB = record
    cbData: DWORD;
    pbData: LPBYTE;
    cUnusedBits: DWORD;
  end;
  {$EXTERNALSYM _CRYPT_BIT_BLOB}
  CRYPT_BIT_BLOB = _CRYPT_BIT_BLOB;
  {$EXTERNALSYM CRYPT_BIT_BLOB}

  PCRYPT_ALGORITHM_IDENTIFIER = ^CRYPT_ALGORITHM_IDENTIFIER;
  {$EXTERNALSYM PCRYPT_ALGORITHM_IDENTIFIER}
  _CRYPT_ALGORITHM_IDENTIFIER = record
    pszObjId: LPSTR;
    Parameters: CRYPT_OBJID_BLOB;
  end;
  {$EXTERNALSYM _CRYPT_ALGORITHM_IDENTIFIER}
  CRYPT_ALGORITHM_IDENTIFIER = _CRYPT_ALGORITHM_IDENTIFIER;
  {$EXTERNALSYM CRYPT_ALGORITHM_IDENTIFIER}

  PCERT_PUBLIC_KEY_INFO = ^CERT_PUBLIC_KEY_INFO;
  {$EXTERNALSYM PCERT_PUBLIC_KEY_INFO}
  _CERT_PUBLIC_KEY_INFO = record
    Algorithm: CRYPT_ALGORITHM_IDENTIFIER;
    PublicKey: CRYPT_BIT_BLOB;
  end;
  {$EXTERNALSYM _CERT_PUBLIC_KEY_INFO}
  CERT_PUBLIC_KEY_INFO = _CERT_PUBLIC_KEY_INFO;
  {$EXTERNALSYM CERT_PUBLIC_KEY_INFO}

  PCERT_EXTENSION = ^CERT_EXTENSION;
  {$EXTERNALSYM PCERT_EXTENSION}
  _CERT_EXTENSION = record
    pszObjId: LPSTR;
    fCritical: BOOL;
    Value: CRYPT_OBJID_BLOB;
  end;
  {$EXTERNALSYM _CERT_EXTENSION}
  CERT_EXTENSION = _CERT_EXTENSION;
  {$EXTERNALSYM CERT_EXTENSION}


  PCERT_INFO = ^CERT_INFO;
  {$EXTERNALSYM PCERT_INFO}
  _CERT_INFO = record
    dwVersion: DWORD;
    SerialNumber: CRYPT_INTEGER_BLOB;
    SignatureAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
    Issuer: CERT_NAME_BLOB;
    NotBefore: FILETIME;
    NotAfter: FILETIME;
    Subject: CERT_NAME_BLOB;
    SubjectPublicKeyInfo: CERT_PUBLIC_KEY_INFO;
    IssuerUniqueId: CRYPT_BIT_BLOB;
    SubjectUniqueId: CRYPT_BIT_BLOB;
    cExtension: DWORD;
    rgExtension: PCERT_EXTENSION;
  end;
  {$EXTERNALSYM _CERT_INFO}
  CERT_INFO = _CERT_INFO;
  {$EXTERNALSYM CERT_INFO}


  HCERTSTORE = Pointer;
  {$EXTERNALSYM HCERTSTORE}
  PCERT_CONTEXT = ^CERT_CONTEXT;

  {$EXTERNALSYM PCERT_CONTEXT}
  _CERT_CONTEXT = record
    dwCertEncodingType: DWORD;
    pbCertEncoded: LPBYTE;
    cbCertEncoded: DWORD;
    pCertInfo: PCERT_INFO;
    hCertStore: HCERTSTORE;
  end;
  {$EXTERNALSYM _CERT_CONTEXT}
  CERT_CONTEXT = _CERT_CONTEXT;
  {$EXTERNALSYM CERT_CONTEXT}
  PCCERT_CONTEXT = PCERT_CONTEXT;
  {$EXTERNALSYM PCCERT_CONTEXT}

const
  Crypt32 = 'Crypt32.dll';

  CERT_CHAIN_FIND_BY_ISSUER_COMPARE_KEY_FLAG         = $0001;
  CERT_CHAIN_FIND_BY_ISSUER_COMPLEX_CHAIN_FLAG       = $0002;
  CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_URL_FLAG      = $0004;
  CERT_CHAIN_FIND_BY_ISSUER_LOCAL_MACHINE_FLAG       = $0008;
  CERT_CHAIN_FIND_BY_ISSUER_NO_KEY_FLAG              = $4000;
  CERT_CHAIN_FIND_BY_ISSUER_CACHE_ONLY_FLAG          = $8000;

  CERT_CHAIN_FIND_BY_ISSUER              = 1;

  CERT_INFO_VERSION_FLAG                 = 1;
  {$EXTERNALSYM CERT_INFO_VERSION_FLAG}
  CERT_INFO_SERIAL_NUMBER_FLAG           = 2;
  {$EXTERNALSYM CERT_INFO_SERIAL_NUMBER_FLAG}
  CERT_INFO_SIGNATURE_ALGORITHM_FLAG     = 3;
  {$EXTERNALSYM CERT_INFO_SIGNATURE_ALGORITHM_FLAG}
  CERT_INFO_ISSUER_FLAG                  = 4;
  {$EXTERNALSYM CERT_INFO_ISSUER_FLAG}
  CERT_INFO_NOT_BEFORE_FLAG              = 5;
  {$EXTERNALSYM CERT_INFO_NOT_BEFORE_FLAG}
  CERT_INFO_NOT_AFTER_FLAG               = 6;
  {$EXTERNALSYM CERT_INFO_NOT_AFTER_FLAG}
  CERT_INFO_SUBJECT_FLAG                 = 7;
  {$EXTERNALSYM CERT_INFO_SUBJECT_FLAG}
  CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG = 8;
  {$EXTERNALSYM CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG}
  CERT_INFO_ISSUER_UNIQUE_ID_FLAG        = 9;
  {$EXTERNALSYM CERT_INFO_ISSUER_UNIQUE_ID_FLAG}
  CERT_INFO_SUBJECT_UNIQUE_ID_FLAG       = 10;
  {$EXTERNALSYM CERT_INFO_SUBJECT_UNIQUE_ID_FLAG}
  CERT_INFO_EXTENSION_FLAG               = 11;
  {$EXTERNALSYM CERT_INFO_EXTENSION_FLAG}
  CERT_COMPARE_MASK           = $FFFF;
  {$EXTERNALSYM CERT_COMPARE_MASK}
  CERT_COMPARE_SHIFT          = 16;
  {$EXTERNALSYM CERT_COMPARE_SHIFT}
  CERT_COMPARE_ANY            = 0;
  {$EXTERNALSYM CERT_COMPARE_ANY}
  CERT_COMPARE_SHA1_HASH      = 1;
  {$EXTERNALSYM CERT_COMPARE_SHA1_HASH}
  CERT_COMPARE_NAME           = 2;
  {$EXTERNALSYM CERT_COMPARE_NAME}
  CERT_COMPARE_ATTR           = 3;
  {$EXTERNALSYM CERT_COMPARE_ATTR}
  CERT_COMPARE_MD5_HASH       = 4;
  {$EXTERNALSYM CERT_COMPARE_MD5_HASH}
  CERT_COMPARE_PROPERTY       = 5;
  {$EXTERNALSYM CERT_COMPARE_PROPERTY}
  CERT_COMPARE_PUBLIC_KEY     = 6;
  {$EXTERNALSYM CERT_COMPARE_PUBLIC_KEY}
  CERT_COMPARE_HASH           = CERT_COMPARE_SHA1_HASH;
  {$EXTERNALSYM CERT_COMPARE_HASH}
  CERT_COMPARE_NAME_STR_A     = 7;
  {$EXTERNALSYM CERT_COMPARE_NAME_STR_A}
  CERT_COMPARE_NAME_STR_W     = 8;
  {$EXTERNALSYM CERT_COMPARE_NAME_STR_W}
  CERT_COMPARE_KEY_SPEC       = 9;
  {$EXTERNALSYM CERT_COMPARE_KEY_SPEC}
  CERT_COMPARE_ENHKEY_USAGE   = 10;
  {$EXTERNALSYM CERT_COMPARE_ENHKEY_USAGE}
  CERT_COMPARE_CTL_USAGE      = CERT_COMPARE_ENHKEY_USAGE;
  {$EXTERNALSYM CERT_COMPARE_CTL_USAGE}
  CERT_COMPARE_SUBJECT_CERT   = 11;
  {$EXTERNALSYM CERT_COMPARE_SUBJECT_CERT}
  CERT_COMPARE_ISSUER_OF      = 12;
  {$EXTERNALSYM CERT_COMPARE_ISSUER_OF}
  CERT_COMPARE_EXISTING       = 13;
  {$EXTERNALSYM CERT_COMPARE_EXISTING}
  CERT_COMPARE_SIGNATURE_HASH = 14;
  {$EXTERNALSYM CERT_COMPARE_SIGNATURE_HASH}
  CERT_COMPARE_KEY_IDENTIFIER = 15;
  {$EXTERNALSYM CERT_COMPARE_KEY_IDENTIFIER}
  CERT_COMPARE_CERT_ID        = 16;
  {$EXTERNALSYM CERT_COMPARE_CERT_ID}
  CERT_FIND_ANY            = CERT_COMPARE_ANY shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_ANY}
  CERT_FIND_SHA1_HASH      = CERT_COMPARE_SHA1_HASH shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_SHA1_HASH}
  CERT_FIND_MD5_HASH       = CERT_COMPARE_MD5_HASH shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_MD5_HASH}
  CERT_FIND_SIGNATURE_HASH = CERT_COMPARE_SIGNATURE_HASH shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_SIGNATURE_HASH}
  CERT_FIND_KEY_IDENTIFIER = CERT_COMPARE_KEY_IDENTIFIER shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_KEY_IDENTIFIER}
  CERT_FIND_HASH           = CERT_FIND_SHA1_HASH;
  {$EXTERNALSYM CERT_FIND_HASH}
  CERT_FIND_PROPERTY       = CERT_COMPARE_PROPERTY shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_PROPERTY}
  CERT_FIND_PUBLIC_KEY     = CERT_COMPARE_PUBLIC_KEY shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_PUBLIC_KEY}
  CERT_FIND_SUBJECT_NAME   = CERT_COMPARE_NAME shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG;
  {$EXTERNALSYM CERT_FIND_SUBJECT_NAME}
  CERT_FIND_SUBJECT_ATTR   = CERT_COMPARE_ATTR shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG;
  {$EXTERNALSYM CERT_FIND_SUBJECT_ATTR}
  CERT_FIND_ISSUER_NAME    = CERT_COMPARE_NAME shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG;
  {$EXTERNALSYM CERT_FIND_ISSUER_NAME}
  CERT_FIND_ISSUER_ATTR    = CERT_COMPARE_ATTR shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG;
  {$EXTERNALSYM CERT_FIND_ISSUER_ATTR}
  CERT_FIND_SUBJECT_STR_A  = CERT_COMPARE_NAME_STR_A shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG;
  {$EXTERNALSYM CERT_FIND_SUBJECT_STR_A}
  CERT_FIND_SUBJECT_STR_W  = CERT_COMPARE_NAME_STR_W shl CERT_COMPARE_SHIFT or CERT_INFO_SUBJECT_FLAG;
  {$EXTERNALSYM CERT_FIND_SUBJECT_STR_W}
  CERT_FIND_SUBJECT_STR    = CERT_FIND_SUBJECT_STR_W;
  {$EXTERNALSYM CERT_FIND_SUBJECT_STR}
  CERT_FIND_ISSUER_STR_A   = CERT_COMPARE_NAME_STR_A shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG;
  {$EXTERNALSYM CERT_FIND_ISSUER_STR_A}
  CERT_FIND_ISSUER_STR_W   = CERT_COMPARE_NAME_STR_W shl CERT_COMPARE_SHIFT or CERT_INFO_ISSUER_FLAG;
  {$EXTERNALSYM CERT_FIND_ISSUER_STR_W}
  CERT_FIND_ISSUER_STR     = CERT_FIND_ISSUER_STR_W;
  {$EXTERNALSYM CERT_FIND_ISSUER_STR}
  CERT_FIND_KEY_SPEC       = CERT_COMPARE_KEY_SPEC shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_KEY_SPEC}
  CERT_FIND_ENHKEY_USAGE   = CERT_COMPARE_ENHKEY_USAGE shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_ENHKEY_USAGE}
  CERT_FIND_CTL_USAGE      = CERT_FIND_ENHKEY_USAGE;
  {$EXTERNALSYM CERT_FIND_CTL_USAGE}

  CERT_FIND_SUBJECT_CERT = CERT_COMPARE_SUBJECT_CERT shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_SUBJECT_CERT}
  CERT_FIND_ISSUER_OF    = CERT_COMPARE_ISSUER_OF shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_ISSUER_OF}
  CERT_FIND_EXISTING     = CERT_COMPARE_EXISTING shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_EXISTING}
  CERT_FIND_CERT_ID      = CERT_COMPARE_CERT_ID shl CERT_COMPARE_SHIFT;
  {$EXTERNALSYM CERT_FIND_CERT_ID}

  CRYPT_ASN_ENCODING  = $00000001;
  {$EXTERNALSYM CRYPT_ASN_ENCODING}
  CRYPT_NDR_ENCODING  = $00000002;
  {$EXTERNALSYM CRYPT_NDR_ENCODING}
  X509_ASN_ENCODING   = $00000001;
  {$EXTERNALSYM X509_ASN_ENCODING}
  X509_NDR_ENCODING   = $00000002;
  {$EXTERNALSYM X509_NDR_ENCODING}
  PKCS_7_ASN_ENCODING = $00010000;
  {$EXTERNALSYM PKCS_7_ASN_ENCODING}
  PKCS_7_NDR_ENCODING = $00020000;
  {$EXTERNALSYM PKCS_7_NDR_ENCODING}

  CERT_SIMPLE_NAME_STR = 1;
  {$EXTERNALSYM CERT_SIMPLE_NAME_STR}

  CERT_NAME_STR_CRLF_FLAG = $08000000;
  {$EXTERNALSYM CERT_NAME_STR_CRLF_FLAG}

type
  _SecPkgContext_IssuerListInfoEx = record
    aIssuers: PCERT_NAME_BLOB;
    cIssuers: DWORD;
  end;
  {$EXTERNALSYM _SecPkgContext_IssuerListInfoEx}
  SecPkgContext_IssuerListInfoEx = _SecPkgContext_IssuerListInfoEx;
  {$EXTERNALSYM SecPkgContext_IssuerListInfoEx}
  PSecPkgContext_IssuerListInfoEx = ^SecPkgContext_IssuerListInfoEx;
  {$EXTERNALSYM PSecPkgContext_IssuerListInfoEx}

  _CERT_TRUST_STATUS = record
    dwErrorStatus: DWORD;
    dwInfoStatus: DWORD;
  end;
  {$EXTERNALSYM _CERT_TRUST_STATUS}
  CERT_TRUST_STATUS = _CERT_TRUST_STATUS;
  {$EXTERNALSYM CERT_TRUST_STATUS}
  PCERT_TRUST_STATUS = ^_CERT_TRUST_STATUS;
  {$EXTERNALSYM PCERT_TRUST_STATUS}


  _CERT_CHAIN_ELEMENT = record
    cbSize: DWORD;
    pCertContext: PCCERT_CONTEXT;
    TrustStatus: CERT_TRUST_STATUS;
    pRevocationInfo: Pointer;//    pRevocationInfo: PCERT_REVOCATION_INFO;
    pIssuanceUsage: Pointer;//    pIssuanceUsage: PCERT_ENHKEY_USAGE;
    pApplicationUsage: Pointer;//    pApplicationUsage: PCERT_ENHKEY_USAGE;
    pwszExtendedErrorInfo: LPCWSTR;
  end;
  {$EXTERNALSYM _CERT_CHAIN_ELEMENT}
  CERT_CHAIN_ELEMENT = _CERT_CHAIN_ELEMENT;
  {$EXTERNALSYM CERT_CHAIN_ELEMENT}
  PCERT_CHAIN_ELEMENT = ^_CERT_CHAIN_ELEMENT;
  {$EXTERNALSYM PCERT_CHAIN_ELEMENT}
  PPCERT_CHAIN_ELEMENT = ^PCERT_CHAIN_ELEMENT;

  _CERT_SIMPLE_CHAIN = record
    cbSize: DWORD;
    TrustStatus: CERT_TRUST_STATUS;
    cElement: DWORD;
    rgpElement: PPCERT_CHAIN_ELEMENT;
    pTrustListInfo: Pointer;//pTrustListInfo: PCERT_TRUST_LIST_INFO;
    fHasRevocationFreshnessTime: BOOL;
    dwRevocationFreshnessTime: DWORD;
  end;
  {$EXTERNALSYM _CERT_SIMPLE_CHAIN}
  CERT_SIMPLE_CHAIN = _CERT_SIMPLE_CHAIN;
  {$EXTERNALSYM CERT_SIMPLE_CHAIN}
  PCERT_SIMPLE_CHAIN = ^_CERT_SIMPLE_CHAIN;
  {$EXTERNALSYM PCERT_SIMPLE_CHAIN}
  PPCERT_SIMPLE_CHAIN = ^PCERT_SIMPLE_CHAIN;


  PCCERT_CHAIN_CONTEXT = ^_CERT_CHAIN_CONTEXT;
  {$EXTERNALSYM PCCERT_CHAIN_CONTEXT}
  PPCCERT_CHAIN_CONTEXT = ^PCCERT_CHAIN_CONTEXT;
  _CERT_CHAIN_CONTEXT = record
    cbSize: DWORD;
    TrustStatus: CERT_TRUST_STATUS;
    cChain: DWORD;
    rgpChain: PPCERT_SIMPLE_CHAIN;
    cLowerQualityChainContext: DWORD;
    rgpLowerQualityChainContext: PPCCERT_CHAIN_CONTEXT;
    fHasRevocationFreshnessTime: BOOL;
    dwRevocationFreshnessTime: DWORD;
  end;
  {$EXTERNALSYM _CERT_CHAIN_CONTEXT}
  CERT_CHAIN_CONTEXT = _CERT_CHAIN_CONTEXT;
  {$EXTERNALSYM CERT_CHAIN_CONTEXT}

  PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK = procedure;

  _CERT_CHAIN_FIND_BY_ISSUER_PARA = record
    cbSize: DWORD;
    pszUsageIdentifier: LPCSTR;
    dwKeySpec: DWORD;
    dwAcquirePrivateKeyFlags: DWORD;
    cIssuer: DWORD;
    rgIssuer: PCERT_NAME_BLOB;
    pfnFindCallback: PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK;
    pvFindArg: Pointer;
    pdwIssuerChainIndex: PDWORD;
    pdwIssuerElementIndex: PDWORD;
  end;
  {$EXTERNALSYM _CERT_CHAIN_FIND_BY_ISSUER_PARA}
  CERT_CHAIN_FIND_BY_ISSUER_PARA = _CERT_CHAIN_FIND_BY_ISSUER_PARA;
  {$EXTERNALSYM CERT_CHAIN_FIND_BY_ISSUER_PARA}
  PCERT_CHAIN_FIND_BY_ISSUER_PARA = ^CERT_CHAIN_FIND_BY_ISSUER_PARA;
  {$EXTERNALSYM PCERT_CHAIN_FIND_BY_ISSUER_PARA}


{$WARN SYMBOL_PLATFORM OFF}

function CertFindCertificateInStore(hCertStore: HCERTSTORE;
  dwCertEncodingType, dwFindFlags, dwFindType: DWORD; pvFindPara: Pointer;
  pPrevCertContext: PCCERT_CHAIN_CONTEXT): PCCERT_CHAIN_CONTEXT; stdcall; external Crypt32 name 'CertFindCertificateInStore'; // delayed;
{$EXTERNALSYM CertFindCertificateInStore}


function CertFindChainInStore(hCertStore: HCERTSTORE;
  dwCertEncodingType, dwFindFlags, dwFindType: DWORD; pvFindPara: Pointer;
  pPrevChainContext: PCCERT_CHAIN_CONTEXT): PCCERT_CHAIN_CONTEXT; stdcall; external Crypt32 name 'CertFindChainInStore'; // delayed;
{$EXTERNALSYM CertFindChainInStore}

function CertOpenSystemStore(hProv: HCRYPTPROV; szSubsystemProtocol: LPCTSTR): HCERTSTORE; stdcall; external Crypt32 name 'CertOpenSystemStoreW'; // delayed;
{$EXTERNALSYM CertOpenSystemStore}

function CertCloseStore(hCertStore: HCERTSTORE; dwFlags: DWORD): BOOL; stdcall; external Crypt32 name 'CertCloseStore'; // delayed;
{$EXTERNALSYM CertCloseStore}

procedure CertFreeCertificateChain(pChainContext: PCCERT_CHAIN_CONTEXT); stdcall; external Crypt32 name 'CertFreeCertificateChain'; // delayed;
{$EXTERNALSYM CertFreeCertificateChain}

function CertDuplicateCertificateContext(pCertContext: PCCERT_CONTEXT): PCCERT_CONTEXT; stdcall; external Crypt32 name 'CertDuplicateCertificateContext'; // delayed;
{$EXTERNALSYM CertDuplicateCertificateContext}

function CertFreeCertificateContext(pCertContext: PCCERT_CONTEXT): BOOL; stdcall; external Crypt32 name 'CertFreeCertificateContext'; // delayed;
{$EXTERNALSYM CertFreeCertificateContext}

function CertNameToStr(dwCertEncodingType: DWORD; pName: PCERT_NAME_BLOB; dwStrType: DWORD; psz: LPTSTR;
  csz: DWORD): DWORD; stdcall; external Crypt32 name 'CertNameToStrW'; // delayed;
{$EXTERNALSYM CertNameToStr}

{ types }

type
  HINTERNET = Pointer;
  {$EXTERNALSYM HINTERNET}
  LPHINTERNET = ^HINTERNET; 
  {$EXTERNALSYM LPHINTERNET}

  INTERNET_PORT = Word;
  {$EXTERNALSYM INTERNET_PORT}
  LPINTERNET_PORT = ^INTERNET_PORT; 
  {$EXTERNALSYM LPINTERNET_PORT}
  TInternetPort = INTERNET_PORT;
  PInternetPort = ^TInternetPort;
  {$IFNDEF UNICODE}
  PNativeUInt = ^NativeUInt;
  {$ENDIF}
{ manifests }


const
  INTERNET_DEFAULT_PORT = 0;                    { use the protocol-specific default }
  {$EXTERNALSYM INTERNET_DEFAULT_PORT}
  INTERNET_DEFAULT_HTTP_PORT = 80;              {    "     "  HTTP   " }
  {$EXTERNALSYM INTERNET_DEFAULT_HTTP_PORT}
  INTERNET_DEFAULT_HTTPS_PORT = 443;            {    "     "  HTTPS  " }
  {$EXTERNALSYM INTERNET_DEFAULT_HTTPS_PORT}

{ flags for WinHttpOpen(): }
  WINHTTP_FLAG_ASYNC = $10000000;               { this session is asynchronous (where supported) }
  {$EXTERNALSYM WINHTTP_FLAG_ASYNC}

{ flags for WinHttpOpenRequest(): }
  WINHTTP_FLAG_SECURE = $00800000;                 { use SSL if applicable (HTTPS) }
  {$EXTERNALSYM WINHTTP_FLAG_SECURE}
  WINHTTP_FLAG_ESCAPE_PERCENT = $00000004;         { if escaping enabled, escape percent as well }
  {$EXTERNALSYM WINHTTP_FLAG_ESCAPE_PERCENT}
  WINHTTP_FLAG_NULL_CODEPAGE = $00000008;          { assume all symbols are ASCII, use fast convertion }
  {$EXTERNALSYM WINHTTP_FLAG_NULL_CODEPAGE}
  WINHTTP_FLAG_BYPASS_PROXY_CACHE = $00000100;    { add "pragma: no-cache" request header }
  {$EXTERNALSYM WINHTTP_FLAG_BYPASS_PROXY_CACHE}
  WINHTTP_FLAG_REFRESH = WINHTTP_FLAG_BYPASS_PROXY_CACHE; 
  {$EXTERNALSYM WINHTTP_FLAG_REFRESH}
  WINHTTP_FLAG_ESCAPE_DISABLE = $00000040;         { disable escaping }
  {$EXTERNALSYM WINHTTP_FLAG_ESCAPE_DISABLE}
  WINHTTP_FLAG_ESCAPE_DISABLE_QUERY = $00000080;   { if escaping enabled escape path part, but do not escape query }
  {$EXTERNALSYM WINHTTP_FLAG_ESCAPE_DISABLE_QUERY}


  SECURITY_FLAG_IGNORE_UNKNOWN_CA = $00000100; 
  {$EXTERNALSYM SECURITY_FLAG_IGNORE_UNKNOWN_CA}
  SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = $00002000;  { expired X509 Cert. }
  {$EXTERNALSYM SECURITY_FLAG_IGNORE_CERT_DATE_INVALID}
  SECURITY_FLAG_IGNORE_CERT_CN_INVALID = $00001000;    { bad common name in X509 Cert. }
  {$EXTERNALSYM SECURITY_FLAG_IGNORE_CERT_CN_INVALID}
  SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE = $00000200; 
  {$EXTERNALSYM SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE}



{ WINHTTP_ASYNC_RESULT - this structure is returned to the application via }
{ the callback with WINHTTP_CALLBACK_STATUS_REQUEST_COMPLETE. It is not sufficient to }
{ just return the result of the async operation. If the API failed then the }
{ app cannot call GetLastError() because the thread context will be incorrect. }
{ Both the value returned by the async API and any resultant error code are }
{ made available. The app need not check dwError if dwResult indicates that }
{ the API succeeded (in this case dwError will be ERROR_SUCCESS) }


type
  WINHTTP_ASYNC_RESULT = record
    dwResult: DWORD_PTR; { indicates which async API has encountered an error }
    dwError: DWORD;      { the error code if the API failed }
  end;
  {$EXTERNALSYM WINHTTP_ASYNC_RESULT}
  LPWINHTTP_ASYNC_RESULT = ^WINHTTP_ASYNC_RESULT;
  {$EXTERNALSYM LPWINHTTP_ASYNC_RESULT}
  TWinHttpAsyncResult = WINHTTP_ASYNC_RESULT;
  PWinHttpAsyncResult = ^TWinHttpAsyncResult;


{ HTTP_VERSION_INFO - query or set global HTTP version (1.0 or 1.1) }

  HTTP_VERSION_INFO = record
    dwMajorVersion: DWORD;
    dwMinorVersion: DWORD;
  end;
  {$EXTERNALSYM HTTP_VERSION_INFO}
  LPHTTP_VERSION_INFO = ^HTTP_VERSION_INFO;
  {$EXTERNALSYM LPHTTP_VERSION_INFO}
  THttpVersionInfo = HTTP_VERSION_INFO;
  PHttpVersionInfo = ^THttpVersionInfo;


{ INTERNET_SCHEME - URL scheme type }

  INTERNET_SCHEME = Integer; 
  LPINTERNET_SCHEME = ^INTERNET_SCHEME;
  {$EXTERNALSYM LPINTERNET_SCHEME}
  {$EXTERNALSYM INTERNET_SCHEME}
  TInternetScheme = INTERNET_SCHEME;
  PInternetScheme = ^TInternetScheme;

const
  INTERNET_SCHEME_HTTP = (1); 
  {$EXTERNALSYM INTERNET_SCHEME_HTTP}
  INTERNET_SCHEME_HTTPS = (2); 
  {$EXTERNALSYM INTERNET_SCHEME_HTTPS}



{ URL_COMPONENTS - the constituent parts of an URL. Used in WinHttpCrackUrl() }
{ and WinHttpCreateUrl() }

{ For WinHttpCrackUrl(), if a pointer field and its corresponding length field }
{ are both 0 then that component is not returned. If the pointer field is NULL }
{ but the length field is not zero, then both the pointer and length fields are }
{ returned if both pointer and corresponding length fields are non-zero then }
{ the pointer field points to a buffer where the component is copied. The }
{ component may be un-escaped, depending on dwFlags }

{ For WinHttpCreateUrl(), the pointer fields should be NULL if the component }
{ is not required. If the corresponding length field is zero then the pointer }
{ field is the address of a zero-terminated string. If the length field is not }
{ zero then it is the string length of the corresponding pointer field }



type
  _URL_COMPONENTS = record
    dwStructSize: DWORD;        { size of this structure. Used in version check }
    lpszScheme: LPWSTR;         { pointer to scheme name }
    dwSchemeLength: DWORD;      { length of scheme name }
    nScheme: INTERNET_SCHEME;   { enumerated scheme type (if known) }
    lpszHostName: LPWSTR;       { pointer to host name }
    dwHostNameLength: DWORD;    { length of host name }
    nPort: INTERNET_PORT;       { converted port number }
    lpszUserName: LPWSTR;       { pointer to user name }
    dwUserNameLength: DWORD;    { length of user name }
    lpszPassword: LPWSTR;       { pointer to password }
    dwPasswordLength: DWORD;    { length of password }
    lpszUrlPath: LPWSTR;        { pointer to URL-path }
    dwUrlPathLength: DWORD;     { length of URL-path }
    lpszExtraInfo: LPWSTR;      { pointer to extra information (e.g. ?foo or #foo) }
    dwExtraInfoLength: DWORD;   { length of extra information }
  end;
  URL_COMPONENTS = _URL_COMPONENTS;
  {$EXTERNALSYM URL_COMPONENTS}
  LPURL_COMPONENTS = ^URL_COMPONENTS;
  {$EXTERNALSYM LPURL_COMPONENTS}
  TURLComponents = URL_COMPONENTS;
  PURLComponents = ^TURLComponents;

  URL_COMPONENTSW = URL_COMPONENTS;
  {$EXTERNALSYM URL_COMPONENTSW}
  LPURL_COMPONENTSW = LPURL_COMPONENTS;
  {$EXTERNALSYM LPURL_COMPONENTSW}
  TURLComponentsW = URL_COMPONENTS;
  PURLComponentsW = ^TURLComponents;



{ WINHTTP_PROXY_INFO - structure supplied with WINHTTP_OPTION_PROXY to get/ }
{ set proxy information on a WinHttpOpen() handle }


  WINHTTP_PROXY_INFO = record
    dwAccessType: DWORD;      { see WINHTTP_ACCESS_* types below }
    lpszProxy: LPWSTR;        { proxy server list }
    lpszProxyBypass: LPWSTR;  { proxy bypass list }
  end;
  {$EXTERNALSYM WINHTTP_PROXY_INFO}
  LPWINHTTP_PROXY_INFO = ^WINHTTP_PROXY_INFO;
  {$EXTERNALSYM LPWINHTTP_PROXY_INFO}
  PWINHTTP_PROXY_INFO = ^WINHTTP_PROXY_INFO;
  TWinHttpProxyInfo = WINHTTP_PROXY_INFO;
  PWinHttpProxyInfo = ^TWinHttpProxyInfo;


  WINHTTP_PROXY_INFOW = WINHTTP_PROXY_INFO; 
  {$EXTERNALSYM WINHTTP_PROXY_INFOW}
  LPWINHTTP_PROXY_INFOW = LPWINHTTP_PROXY_INFO;
  {$EXTERNALSYM LPWINHTTP_PROXY_INFOW}
  TWinHttpProxyInfoW = WINHTTP_PROXY_INFO;
  PWinHttpProxyInfoW = ^TWinHttpProxyInfo;


  WINHTTP_AUTOPROXY_OPTIONS = record
    dwFlags: DWORD;
    dwAutoDetectFlags: DWORD;
    lpszAutoConfigUrl: LPCWSTR;
    lpvReserved: Pointer;
    dwReserved: DWORD;
    fAutoLogonIfChallenged: BOOL;
  end;
  {$EXTERNALSYM WINHTTP_AUTOPROXY_OPTIONS}
  PWINHTTP_AUTOPROXY_OPTIONS = ^WINHTTP_AUTOPROXY_OPTIONS;
  TWinHttpAutoProxyOptions = WINHTTP_AUTOPROXY_OPTIONS;
  PWinHttpAutoProxyOptions = ^TWinHttpAutoProxyOptions;


const
  WINHTTP_AUTOPROXY_AUTO_DETECT = $00000001; 
  {$EXTERNALSYM WINHTTP_AUTOPROXY_AUTO_DETECT}
  WINHTTP_AUTOPROXY_CONFIG_URL = $00000002; 
  {$EXTERNALSYM WINHTTP_AUTOPROXY_CONFIG_URL}
  WINHTTP_AUTOPROXY_HOST_KEEPCASE = $00000004; 
  {$EXTERNALSYM WINHTTP_AUTOPROXY_HOST_KEEPCASE}
  WINHTTP_AUTOPROXY_HOST_LOWERCASE = $00000008; 
  {$EXTERNALSYM WINHTTP_AUTOPROXY_HOST_LOWERCASE}
  WINHTTP_AUTOPROXY_RUN_INPROCESS = $00010000; 
  {$EXTERNALSYM WINHTTP_AUTOPROXY_RUN_INPROCESS}
  WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY = $00020000; 
  {$EXTERNALSYM WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY}


{ Flags for dwAutoDetectFlags }

  WINHTTP_AUTO_DETECT_TYPE_DHCP = $00000001;
  {$EXTERNALSYM WINHTTP_AUTO_DETECT_TYPE_DHCP}
  WINHTTP_AUTO_DETECT_TYPE_DNS_A = $00000002; 
  {$EXTERNALSYM WINHTTP_AUTO_DETECT_TYPE_DNS_A}


{ WINHTTP_CERTIFICATE_INFO lpBuffer - contains the certificate returned from }
{ the server }


type
  WINHTTP_CERTIFICATE_INFO = record { ftExpiry - date the certificate expires. }

    ftExpiry: FILETIME;

    { ftStart - date the certificate becomes valid. }
    ftStart: FILETIME;

    { lpszSubjectInfo - the name of organization, site, and server }
    {   the cert. was issued for. }
    lpszSubjectInfo: LPWSTR;

    { lpszIssuerInfo - the name of orgainzation, site, and server }
    {   the cert was issues by. }
    lpszIssuerInfo: LPWSTR;

    { lpszProtocolName - the name of the protocol used to provide the secure }
    {   connection. }
    lpszProtocolName: LPWSTR;

    { lpszSignatureAlgName - the name of the algorithm used for signing }
    {  the certificate. }
    lpszSignatureAlgName: LPWSTR;

    { lpszEncryptionAlgName - the name of the algorithm used for }
    {  doing encryption over the secure channel (SSL) connection. }
    lpszEncryptionAlgName: LPWSTR;

    { dwKeySize - size of the key. }
    dwKeySize: DWORD;
  end;
  {$EXTERNALSYM WINHTTP_CERTIFICATE_INFO}
  TWinHttpCertificateInfo = WINHTTP_CERTIFICATE_INFO;
  PWinHttpCertificateInfo = ^TWinHttpCertificateInfo;


  WINHTTP_CONNECTION_INFO = record
    cbSize: DWORD;
    LocalAddress: SOCKADDR_STORAGE; { local ip, local port }
    RemoteAddress: SOCKADDR_STORAGE;{ remote ip, remote port }
  end;
  {$EXTERNALSYM WINHTTP_CONNECTION_INFO}
  TWinHttpConnectionInfo = WINHTTP_CONNECTION_INFO;
  PWinHttpConnectionInfo = ^TWinHttpConnectionInfo;


{ prototypes }

{ constants for WinHttpTimeFromSystemTime }

const
  WINHTTP_TIME_FORMAT_BUFSIZE = 62;
  {$EXTERNALSYM WINHTTP_TIME_FORMAT_BUFSIZE}

function WinHttpTimeFromSystemTime(var pst: TSystemTime; pwszTime: LPWSTR): BOOL; stdcall;
{$EXTERNALSYM WinHttpTimeFromSystemTime}

function WinHttpTimeToSystemTime(pwszTime: LPCWSTR; out pst: TSystemTime): BOOL; stdcall;
{$EXTERNALSYM WinHttpTimeToSystemTime}

{ flags for CrackUrl() and CombineUrl() }


const
  ICU_NO_ENCODE = $20000000;    { Don't convert unsafe characters to escape sequence }
  {$EXTERNALSYM ICU_NO_ENCODE}
  ICU_DECODE = $10000000;       { Convert %XX escape sequences to characters }
  {$EXTERNALSYM ICU_DECODE}
  ICU_NO_META = $08000000;      { Don't convert .. etc. meta path sequences }
  {$EXTERNALSYM ICU_NO_META}
  ICU_ENCODE_SPACES_ONLY = $04000000;  { Encode spaces only }
  {$EXTERNALSYM ICU_ENCODE_SPACES_ONLY}
  ICU_BROWSER_MODE = $02000000; { Special encode/decode rules for browser }
  {$EXTERNALSYM ICU_BROWSER_MODE}
  ICU_ENCODE_PERCENT = $00001000;           { Encode any percent (ASCII25) }
  {$EXTERNALSYM ICU_ENCODE_PERCENT}

        { signs encountered, default is to not encode percent. }


function WinHttpCrackUrl(pwszUrl: LPCWSTR; dwUrlLength: DWORD; dwFlags: DWORD;
  var lpUrlComponents: TURLComponents): BOOL; stdcall;
{$EXTERNALSYM WinHttpCrackUrl}

function WinHttpCreateUrl(var lpUrlComponents: TURLComponents; dwFlags: DWORD; pwszUrl: LPWSTR;
  var pdwUrlLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpCreateUrl}


{ flags for WinHttpCrackUrl() and WinHttpCreateUrl() }

const
  ICU_ESCAPE = $80000000;       { (un)escape URL characters }
  {$EXTERNALSYM ICU_ESCAPE}
  ICU_ESCAPE_AUTHORITY = $00002000; { causes InternetCreateUrlA to escape chars in authority components (user, pwd, host) }
  {$EXTERNALSYM ICU_ESCAPE_AUTHORITY}
  ICU_REJECT_USERPWD = $00004000;   { rejects usrls whick have username/pwd sections }
  {$EXTERNALSYM ICU_REJECT_USERPWD}

function WinHttpCheckPlatform: BOOL; stdcall;
{$EXTERNALSYM WinHttpCheckPlatform}


function WinHttpGetDefaultProxyConfiguration(var pProxyInfo: TWinHttpProxyInfo): BOOL; stdcall;
{$EXTERNALSYM WinHttpGetDefaultProxyConfiguration}
function WinHttpSetDefaultProxyConfiguration(var pProxyInfo: TWinHttpProxyInfo): BOOL; stdcall;
{$EXTERNALSYM WinHttpSetDefaultProxyConfiguration}

function WinHttpOpen(pszAgentW: LPCWSTR; dwAccessType: DWORD; pszProxyW: LPCWSTR; pszProxyBypassW: LPCWSTR;
  dwFlags: DWORD): HINTERNET; stdcall;
{$EXTERNALSYM WinHttpOpen}

{ WinHttpOpen dwAccessType values (also for WINHTTP_PROXY_INFO::dwAccessType) }
const
  WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0;
  {$EXTERNALSYM WINHTTP_ACCESS_TYPE_DEFAULT_PROXY}
  WINHTTP_ACCESS_TYPE_NO_PROXY = 1;
  {$EXTERNALSYM WINHTTP_ACCESS_TYPE_NO_PROXY}
  WINHTTP_ACCESS_TYPE_NAMED_PROXY = 3;
  {$EXTERNALSYM WINHTTP_ACCESS_TYPE_NAMED_PROXY}

{ WinHttpOpen prettifiers for optional parameters }
  WINHTTP_NO_PROXY_NAME = nil;
  {$EXTERNALSYM WINHTTP_NO_PROXY_NAME}
  WINHTTP_NO_PROXY_BYPASS = nil;
  {$EXTERNALSYM WINHTTP_NO_PROXY_BYPASS}

function WinHttpCloseHandle(hInternet: HINTERNET): BOOL; stdcall;
{$EXTERNALSYM WinHttpCloseHandle}


function WinHttpConnect(hSession: HINTERNET; pswzServerName: LPCWSTR; nServerPort: INTERNET_PORT;
  dwReserved: DWORD): HINTERNET; stdcall;
{$EXTERNALSYM WinHttpConnect}


function WinHttpReadData(hRequest: HINTERNET; out lpBuffer; dwNumberOfBytesToRead: DWORD;
  lpdwNumberOfBytesRead: LPDWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpReadData}

function WinHttpWriteData(hRequest: HINTERNET; out lpBuffer; dwNumberOfBytesToWrite: DWORD;
  lpdwNumberOfBytesWritten: LPDWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpWriteData}


function WinHttpQueryDataAvailable(hRequest: HINTERNET;
  lpdwNumberOfBytesAvailable: LPDWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpQueryDataAvailable}


function WinHttpQueryOption(hInternet: HINTERNET; dwOption: DWORD; out lpBuffer; var lpdwBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpQueryOption}

const
  WINHTTP_NO_CLIENT_CERT_CONTEXT = nil;
  {$EXTERNALSYM WINHTTP_NO_CLIENT_CERT_CONTEXT}

function WinHttpSetOption(hInternet: HINTERNET; dwOption: DWORD;
  lpBuffer: Pointer; dwBufferLength: DWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpSetOption}

function WinHttpSetTimeouts(hInternet: HINTERNET; nResolveTimeout: Integer; nConnectTimeout: Integer;
  nSendTimeout: Integer; nReceiveTimeout: Integer): BOOL; stdcall;
{$EXTERNALSYM WinHttpSetTimeouts}

function WinHttpIsHostInProxyBypassList(var pProxyInfo: TWinHttpProxyInfo; pwszHost: LPCWSTR;
  tScheme: TInternetScheme; nPort: TInternetPort; out pfIsInBypassList: BOOL): DWORD; stdcall;
{$EXTERNALSYM WinHttpIsHostInProxyBypassList}


{ options manifests for WinHttp(Query|Set)Option }


const
  WINHTTP_OPTION_CALLBACK = 1;
  {$EXTERNALSYM WINHTTP_OPTION_CALLBACK}
  WINHTTP_OPTION_RESOLVE_TIMEOUT = 2;
  {$EXTERNALSYM WINHTTP_OPTION_RESOLVE_TIMEOUT}
  WINHTTP_OPTION_CONNECT_TIMEOUT = 3;
  {$EXTERNALSYM WINHTTP_OPTION_CONNECT_TIMEOUT}
  WINHTTP_OPTION_CONNECT_RETRIES = 4;
  {$EXTERNALSYM WINHTTP_OPTION_CONNECT_RETRIES}
  WINHTTP_OPTION_SEND_TIMEOUT = 5;
  {$EXTERNALSYM WINHTTP_OPTION_SEND_TIMEOUT}
  WINHTTP_OPTION_RECEIVE_TIMEOUT = 6;
  {$EXTERNALSYM WINHTTP_OPTION_RECEIVE_TIMEOUT}
  WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT = 7;
  {$EXTERNALSYM WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT}
  WINHTTP_OPTION_HANDLE_TYPE = 9;
  {$EXTERNALSYM WINHTTP_OPTION_HANDLE_TYPE}
  WINHTTP_OPTION_READ_BUFFER_SIZE = 12;
  {$EXTERNALSYM WINHTTP_OPTION_READ_BUFFER_SIZE}
  WINHTTP_OPTION_WRITE_BUFFER_SIZE = 13;
  {$EXTERNALSYM WINHTTP_OPTION_WRITE_BUFFER_SIZE}
  WINHTTP_OPTION_PARENT_HANDLE = 21;
  {$EXTERNALSYM WINHTTP_OPTION_PARENT_HANDLE}
  WINHTTP_OPTION_EXTENDED_ERROR = 24;
  {$EXTERNALSYM WINHTTP_OPTION_EXTENDED_ERROR}
  WINHTTP_OPTION_SECURITY_FLAGS = 31;
  {$EXTERNALSYM WINHTTP_OPTION_SECURITY_FLAGS}
  WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT = 32;
  {$EXTERNALSYM WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT}
  WINHTTP_OPTION_URL = 34;
  {$EXTERNALSYM WINHTTP_OPTION_URL}
  WINHTTP_OPTION_SECURITY_KEY_BITNESS = 36;
  {$EXTERNALSYM WINHTTP_OPTION_SECURITY_KEY_BITNESS}
  WINHTTP_OPTION_PROXY = 38;
  {$EXTERNALSYM WINHTTP_OPTION_PROXY}


  WINHTTP_OPTION_USER_AGENT = 41;
  {$EXTERNALSYM WINHTTP_OPTION_USER_AGENT}
  WINHTTP_OPTION_CONTEXT_VALUE = 45;
  {$EXTERNALSYM WINHTTP_OPTION_CONTEXT_VALUE}
  WINHTTP_OPTION_CLIENT_CERT_CONTEXT = 47;
  {$EXTERNALSYM WINHTTP_OPTION_CLIENT_CERT_CONTEXT}
  WINHTTP_OPTION_REQUEST_PRIORITY = 58;
  {$EXTERNALSYM WINHTTP_OPTION_REQUEST_PRIORITY}
  WINHTTP_OPTION_HTTP_VERSION = 59;
  {$EXTERNALSYM WINHTTP_OPTION_HTTP_VERSION}
  WINHTTP_OPTION_DISABLE_FEATURE = 63;
  {$EXTERNALSYM WINHTTP_OPTION_DISABLE_FEATURE}

  WINHTTP_OPTION_CODEPAGE = 68;
  {$EXTERNALSYM WINHTTP_OPTION_CODEPAGE}
  WINHTTP_OPTION_MAX_CONNS_PER_SERVER = 73;
  {$EXTERNALSYM WINHTTP_OPTION_MAX_CONNS_PER_SERVER}
  WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER = 74;
  {$EXTERNALSYM WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER}
  WINHTTP_OPTION_AUTOLOGON_POLICY = 77;
  {$EXTERNALSYM WINHTTP_OPTION_AUTOLOGON_POLICY}
  WINHTTP_OPTION_SERVER_CERT_CONTEXT = 78;
  {$EXTERNALSYM WINHTTP_OPTION_SERVER_CERT_CONTEXT}
  WINHTTP_OPTION_ENABLE_FEATURE = 79;
  {$EXTERNALSYM WINHTTP_OPTION_ENABLE_FEATURE}
  WINHTTP_OPTION_WORKER_THREAD_COUNT = 80;
  {$EXTERNALSYM WINHTTP_OPTION_WORKER_THREAD_COUNT}
  WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT = 81;
  {$EXTERNALSYM WINHTTP_OPTION_PASSPORT_COBRANDING_TEXT}
  WINHTTP_OPTION_PASSPORT_COBRANDING_URL = 82;
  {$EXTERNALSYM WINHTTP_OPTION_PASSPORT_COBRANDING_URL}
  WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH = 83;
  {$EXTERNALSYM WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH}
  WINHTTP_OPTION_SECURE_PROTOCOLS = 84;
  {$EXTERNALSYM WINHTTP_OPTION_SECURE_PROTOCOLS}
  WINHTTP_OPTION_ENABLETRACING = 85;
  {$EXTERNALSYM WINHTTP_OPTION_ENABLETRACING}
  WINHTTP_OPTION_PASSPORT_SIGN_OUT = 86;
  {$EXTERNALSYM WINHTTP_OPTION_PASSPORT_SIGN_OUT}
  WINHTTP_OPTION_PASSPORT_RETURN_URL = 87;
  {$EXTERNALSYM WINHTTP_OPTION_PASSPORT_RETURN_URL}
  WINHTTP_OPTION_REDIRECT_POLICY = 88;
  {$EXTERNALSYM WINHTTP_OPTION_REDIRECT_POLICY}
  WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS = 89;
  {$EXTERNALSYM WINHTTP_OPTION_MAX_HTTP_AUTOMATIC_REDIRECTS}
  WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE = 90;
  {$EXTERNALSYM WINHTTP_OPTION_MAX_HTTP_STATUS_CONTINUE}
  WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE = 91;
  {$EXTERNALSYM WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE}
  WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE = 92;
  {$EXTERNALSYM WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE}
  WINHTTP_OPTION_CONNECTION_INFO = 93;
  {$EXTERNALSYM WINHTTP_OPTION_CONNECTION_INFO}
  WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST = 94;
  {$EXTERNALSYM WINHTTP_OPTION_CLIENT_CERT_ISSUER_LIST}
  WINHTTP_OPTION_SPN = 96;
  {$EXTERNALSYM WINHTTP_OPTION_SPN}

  WINHTTP_OPTION_GLOBAL_PROXY_CREDS = 97;
  {$EXTERNALSYM WINHTTP_OPTION_GLOBAL_PROXY_CREDS}
  WINHTTP_OPTION_GLOBAL_SERVER_CREDS = 98;
  {$EXTERNALSYM WINHTTP_OPTION_GLOBAL_SERVER_CREDS}

  WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT = 99;
  {$EXTERNALSYM WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT}
  WINHTTP_OPTION_REJECT_USERPWD_IN_URL = 100;
  {$EXTERNALSYM WINHTTP_OPTION_REJECT_USERPWD_IN_URL}
  WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS = 101;
  {$EXTERNALSYM WINHTTP_OPTION_USE_GLOBAL_SERVER_CREDENTIALS}


  WINHTTP_OPTION_RECEIVE_PROXY_CONNECT_RESPONSE = 103;
  {$EXTERNALSYM WINHTTP_OPTION_RECEIVE_PROXY_CONNECT_RESPONSE}
  WINHTTP_OPTION_IS_PROXY_CONNECT_RESPONSE = 104;
  {$EXTERNALSYM WINHTTP_OPTION_IS_PROXY_CONNECT_RESPONSE}


  WINHTTP_OPTION_SERVER_SPN_USED = 106;
  {$EXTERNALSYM WINHTTP_OPTION_SERVER_SPN_USED}
  WINHTTP_OPTION_PROXY_SPN_USED = 107;
  {$EXTERNALSYM WINHTTP_OPTION_PROXY_SPN_USED}

  WINHTTP_OPTION_SERVER_CBT = 108;
  {$EXTERNALSYM WINHTTP_OPTION_SERVER_CBT}


  WINHTTP_FIRST_OPTION = WINHTTP_OPTION_CALLBACK;
  {$EXTERNALSYM WINHTTP_FIRST_OPTION}

  WINHTTP_LAST_OPTION = WINHTTP_OPTION_SERVER_CBT;
  {$EXTERNALSYM WINHTTP_LAST_OPTION}

  WINHTTP_OPTION_USERNAME = $1000;
  {$EXTERNALSYM WINHTTP_OPTION_USERNAME}
  WINHTTP_OPTION_PASSWORD = $1001;
  {$EXTERNALSYM WINHTTP_OPTION_PASSWORD}
  WINHTTP_OPTION_PROXY_USERNAME = $1002;
  {$EXTERNALSYM WINHTTP_OPTION_PROXY_USERNAME}
  WINHTTP_OPTION_PROXY_PASSWORD = $1003;
  {$EXTERNALSYM WINHTTP_OPTION_PROXY_PASSWORD}


{ manifest value for WINHTTP_OPTION_MAX_CONNS_PER_SERVER and WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER }
  WINHTTP_CONNS_PER_SERVER_UNLIMITED = $FFFFFFFF;
  {$EXTERNALSYM WINHTTP_CONNS_PER_SERVER_UNLIMITED}


{ values for WINHTTP_OPTION_AUTOLOGON_POLICY }
  WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM = 0;
  {$EXTERNALSYM WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM}
  WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW = 1;
  {$EXTERNALSYM WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW}
  WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH = 2;
  {$EXTERNALSYM WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH}

  WINHTTP_AUTOLOGON_SECURITY_LEVEL_DEFAULT = WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM;
  {$EXTERNALSYM WINHTTP_AUTOLOGON_SECURITY_LEVEL_DEFAULT}

{ values for WINHTTP_OPTION_REDIRECT_POLICY }
  WINHTTP_OPTION_REDIRECT_POLICY_NEVER = 0;
  {$EXTERNALSYM WINHTTP_OPTION_REDIRECT_POLICY_NEVER}
  WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP = 1;
  {$EXTERNALSYM WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP}
  WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS = 2;
  {$EXTERNALSYM WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS}

  WINHTTP_OPTION_REDIRECT_POLICY_LAST = WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS;
  {$EXTERNALSYM WINHTTP_OPTION_REDIRECT_POLICY_LAST}
  WINHTTP_OPTION_REDIRECT_POLICY_DEFAULT = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
  {$EXTERNALSYM WINHTTP_OPTION_REDIRECT_POLICY_DEFAULT}

  WINHTTP_DISABLE_PASSPORT_AUTH = $00000000;
  {$EXTERNALSYM WINHTTP_DISABLE_PASSPORT_AUTH}
  WINHTTP_ENABLE_PASSPORT_AUTH = $10000000;
  {$EXTERNALSYM WINHTTP_ENABLE_PASSPORT_AUTH}
  WINHTTP_DISABLE_PASSPORT_KEYRING = $20000000;
  {$EXTERNALSYM WINHTTP_DISABLE_PASSPORT_KEYRING}
  WINHTTP_ENABLE_PASSPORT_KEYRING = $40000000;
  {$EXTERNALSYM WINHTTP_ENABLE_PASSPORT_KEYRING}


{ values for WINHTTP_OPTION_DISABLE_FEATURE }
  WINHTTP_DISABLE_COOKIES = $00000001;
  {$EXTERNALSYM WINHTTP_DISABLE_COOKIES}
  WINHTTP_DISABLE_REDIRECTS = $00000002;
  {$EXTERNALSYM WINHTTP_DISABLE_REDIRECTS}
  WINHTTP_DISABLE_AUTHENTICATION = $00000004;
  {$EXTERNALSYM WINHTTP_DISABLE_AUTHENTICATION}
  WINHTTP_DISABLE_KEEP_ALIVE = $00000008;
  {$EXTERNALSYM WINHTTP_DISABLE_KEEP_ALIVE}

{ values for WINHTTP_OPTION_ENABLE_FEATURE }
  WINHTTP_ENABLE_SSL_REVOCATION = $00000001;
  {$EXTERNALSYM WINHTTP_ENABLE_SSL_REVOCATION}
  WINHTTP_ENABLE_SSL_REVERT_IMPERSONATION = $00000002;
  {$EXTERNALSYM WINHTTP_ENABLE_SSL_REVERT_IMPERSONATION}

{ values for WINHTTP_OPTION_SPN }
  WINHTTP_DISABLE_SPN_SERVER_PORT = $00000000;
  {$EXTERNALSYM WINHTTP_DISABLE_SPN_SERVER_PORT}
  WINHTTP_ENABLE_SPN_SERVER_PORT = $00000001;
  {$EXTERNALSYM WINHTTP_ENABLE_SPN_SERVER_PORT}
  WINHTTP_OPTION_SPN_MASK = WINHTTP_ENABLE_SPN_SERVER_PORT;
  {$EXTERNALSYM WINHTTP_OPTION_SPN_MASK}

type
  PWINHTTP_CREDS = ^WINHTTP_CREDS;
  WINHTTP_CREDS = record
    lpszUserName: LPSTR;
    lpszPassword: LPSTR;
    lpszRealm: LPSTR;
    dwAuthScheme: DWORD;
    lpszHostName: LPSTR;
    dwPort: DWORD;
  end;
  tagWINHTTP_CREDS = WINHTTP_CREDS;
  {$EXTERNALSYM WINHTTP_CREDS}
  {$EXTERNALSYM PWINHTTP_CREDS}
  TWinHttpCreds = WINHTTP_CREDS;
  PWinHttpCreds = ^TWinHttpCreds;

{ structure for WINHTTP_OPTION_GLOBAL_SERVER_CREDS and }
{ WINHTTP_OPTION_GLOBAL_PROXY_CREDS }
  PWINHTTP_CREDS_EX = ^WINHTTP_CREDS_EX;
  WINHTTP_CREDS_EX = record
    lpszUserName: LPSTR;
    lpszPassword: LPSTR;
    lpszRealm: LPSTR;
    dwAuthScheme: DWORD;
    lpszHostName: LPSTR;
    dwPort: DWORD;
    lpszUrl: LPSTR;
  end;
  tagWINHTTP_CREDS_EX = WINHTTP_CREDS_EX;
  {$EXTERNALSYM WINHTTP_CREDS_EX}
  {$EXTERNALSYM PWINHTTP_CREDS_EX}
  TWinHttpCredsEx = WINHTTP_CREDS_EX;
  PWinHttpCredsEx = ^TWinHttpCredsEx;


{ winhttp handle types }

const
  WINHTTP_HANDLE_TYPE_SESSION = 1;
  {$EXTERNALSYM WINHTTP_HANDLE_TYPE_SESSION}
  WINHTTP_HANDLE_TYPE_CONNECT = 2;
  {$EXTERNALSYM WINHTTP_HANDLE_TYPE_CONNECT}
  WINHTTP_HANDLE_TYPE_REQUEST = 3;
  {$EXTERNALSYM WINHTTP_HANDLE_TYPE_REQUEST}


{ values for auth schemes }

  WINHTTP_AUTH_SCHEME_BASIC = $00000001;
  {$EXTERNALSYM WINHTTP_AUTH_SCHEME_BASIC}
  WINHTTP_AUTH_SCHEME_NTLM = $00000002;
  {$EXTERNALSYM WINHTTP_AUTH_SCHEME_NTLM}
  WINHTTP_AUTH_SCHEME_PASSPORT = $00000004;
  {$EXTERNALSYM WINHTTP_AUTH_SCHEME_PASSPORT}
  WINHTTP_AUTH_SCHEME_DIGEST = $00000008;
  {$EXTERNALSYM WINHTTP_AUTH_SCHEME_DIGEST}
  WINHTTP_AUTH_SCHEME_NEGOTIATE = $00000010;
  {$EXTERNALSYM WINHTTP_AUTH_SCHEME_NEGOTIATE}

{ WinHttp supported Authentication Targets }

  WINHTTP_AUTH_TARGET_SERVER = $00000000;
  {$EXTERNALSYM WINHTTP_AUTH_TARGET_SERVER}
  WINHTTP_AUTH_TARGET_PROXY = $00000001;
  {$EXTERNALSYM WINHTTP_AUTH_TARGET_PROXY}


{ values for WINHTTP_OPTION_SECURITY_FLAGS }


{ query only }
  SECURITY_FLAG_SECURE = $00000001;                    { can query only }
  {$EXTERNALSYM SECURITY_FLAG_SECURE}
  SECURITY_FLAG_STRENGTH_WEAK = $10000000;
  {$EXTERNALSYM SECURITY_FLAG_STRENGTH_WEAK}
  SECURITY_FLAG_STRENGTH_MEDIUM = $40000000;
  {$EXTERNALSYM SECURITY_FLAG_STRENGTH_MEDIUM}
  SECURITY_FLAG_STRENGTH_STRONG = $20000000;
  {$EXTERNALSYM SECURITY_FLAG_STRENGTH_STRONG}



{ Secure connection error status flags }
  WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED = $00000001;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED}
  WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT = $00000002;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT}
  WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED = $00000004;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED}
  WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA = $00000008;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA}
  WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID = $00000010;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID}
  WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID = $00000020;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID}
  WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE = $00000040;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_CERT_WRONG_USAGE}
  WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR = $80000000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR}


  WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 = $00000008;
  {$EXTERNALSYM WINHTTP_FLAG_SECURE_PROTOCOL_SSL2}
  WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 = $00000020;
  {$EXTERNALSYM WINHTTP_FLAG_SECURE_PROTOCOL_SSL3}
  WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 = $00000080;
  {$EXTERNALSYM WINHTTP_FLAG_SECURE_PROTOCOL_TLS1}
  WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 = $00000200;
  {$EXTERNALSYM WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1}
  WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 = $00000800;
  {$EXTERNALSYM WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2}
  WINHTTP_FLAG_SECURE_PROTOCOL_ALL = WINHTTP_FLAG_SECURE_PROTOCOL_SSL2 or
                                             WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 or
                                             WINHTTP_FLAG_SECURE_PROTOCOL_TLS1;
  {$EXTERNALSYM WINHTTP_FLAG_SECURE_PROTOCOL_ALL}



{ callback function for WinHttpSetStatusCallback }


type
  LPWINHTTP_STATUS_CALLBACK = ^WINHTTP_STATUS_CALLBACK;
  WINHTTP_STATUS_CALLBACK = procedure(hInternet: HINTERNET; dwContext: Pointer; dwInternetStatus: DWORD;
    lpvStatusInformation: Pointer; dwStatusInformationLength: DWORD); stdcall;
{$EXTERNALSYM WINHTTP_STATUS_CALLBACK}
{$EXTERNALSYM LPWINHTTP_STATUS_CALLBACK}
  TWinHttpStatusCallback = WINHTTP_STATUS_CALLBACK;
  PWinHttpStatusCallback = ^TWinHttpStatusCallback;



function WinHttpSetStatusCallback(hInternet: HINTERNET;
  lpfnInternetCallback: TWinHttpStatusCallback; dwNotificationFlags: DWORD;
  dwReserved: PNativeUInt): TWinHttpStatusCallback; stdcall;
{$EXTERNALSYM WinHttpSetStatusCallback}



{ status manifests for WinHttp status callback }


const
  WINHTTP_CALLBACK_STATUS_RESOLVING_NAME = $00000001;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_RESOLVING_NAME}
  WINHTTP_CALLBACK_STATUS_NAME_RESOLVED = $00000002;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_NAME_RESOLVED}
  WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER = $00000004;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER}
  WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER = $00000008;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER}
  WINHTTP_CALLBACK_STATUS_SENDING_REQUEST = $00000010;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_SENDING_REQUEST}
  WINHTTP_CALLBACK_STATUS_REQUEST_SENT = $00000020;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_REQUEST_SENT}
  WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE = $00000040;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE}
  WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED = $00000080;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED}
  WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION = $00000100;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION}
  WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED = $00000200;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED}
  WINHTTP_CALLBACK_STATUS_HANDLE_CREATED = $00000400;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_HANDLE_CREATED}
  WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING = $00000800;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING}
  WINHTTP_CALLBACK_STATUS_DETECTING_PROXY = $00001000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_DETECTING_PROXY}
  WINHTTP_CALLBACK_STATUS_REDIRECT = $00004000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_REDIRECT}
  WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE = $00008000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE}
  WINHTTP_CALLBACK_STATUS_SECURE_FAILURE = $00010000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_SECURE_FAILURE}
  WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE = $00020000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE}
  WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE = $00040000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE}
  WINHTTP_CALLBACK_STATUS_READ_COMPLETE = $00080000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_READ_COMPLETE}
  WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE = $00100000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE}
  WINHTTP_CALLBACK_STATUS_REQUEST_ERROR = $00200000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_REQUEST_ERROR}
  WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE = $00400000;
  {$EXTERNALSYM WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE}


{ API Enums for WINHTTP_CALLBACK_STATUS_REQUEST_ERROR: }
  API_RECEIVE_RESPONSE = (1);
  {$EXTERNALSYM API_RECEIVE_RESPONSE}
  API_QUERY_DATA_AVAILABLE = (2);
  {$EXTERNALSYM API_QUERY_DATA_AVAILABLE}
  API_READ_DATA = (3);
  {$EXTERNALSYM API_READ_DATA}
  API_WRITE_DATA = (4);
  {$EXTERNALSYM API_WRITE_DATA}
  API_SEND_REQUEST = (5);
  {$EXTERNALSYM API_SEND_REQUEST}


  WINHTTP_CALLBACK_FLAG_RESOLVE_NAME = WINHTTP_CALLBACK_STATUS_RESOLVING_NAME or WINHTTP_CALLBACK_STATUS_NAME_RESOLVED;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_RESOLVE_NAME}
  WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER = WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER or WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_CONNECT_TO_SERVER}
  WINHTTP_CALLBACK_FLAG_SEND_REQUEST = WINHTTP_CALLBACK_STATUS_SENDING_REQUEST or WINHTTP_CALLBACK_STATUS_REQUEST_SENT;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_SEND_REQUEST}
  WINHTTP_CALLBACK_FLAG_RECEIVE_RESPONSE = WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE or WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_RECEIVE_RESPONSE}
  WINHTTP_CALLBACK_FLAG_CLOSE_CONNECTION = WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION or WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_CLOSE_CONNECTION}
  WINHTTP_CALLBACK_FLAG_HANDLES = WINHTTP_CALLBACK_STATUS_HANDLE_CREATED or WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_HANDLES}
  WINHTTP_CALLBACK_FLAG_DETECTING_PROXY = WINHTTP_CALLBACK_STATUS_DETECTING_PROXY;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_DETECTING_PROXY}
  WINHTTP_CALLBACK_FLAG_REDIRECT = WINHTTP_CALLBACK_STATUS_REDIRECT;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_REDIRECT}
  WINHTTP_CALLBACK_FLAG_INTERMEDIATE_RESPONSE = WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_INTERMEDIATE_RESPONSE}
  WINHTTP_CALLBACK_FLAG_SECURE_FAILURE = WINHTTP_CALLBACK_STATUS_SECURE_FAILURE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_SECURE_FAILURE}
  WINHTTP_CALLBACK_FLAG_SENDREQUEST_COMPLETE = WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_SENDREQUEST_COMPLETE}
  WINHTTP_CALLBACK_FLAG_HEADERS_AVAILABLE = WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_HEADERS_AVAILABLE}
  WINHTTP_CALLBACK_FLAG_DATA_AVAILABLE = WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_DATA_AVAILABLE}
  WINHTTP_CALLBACK_FLAG_READ_COMPLETE = WINHTTP_CALLBACK_STATUS_READ_COMPLETE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_READ_COMPLETE}
  WINHTTP_CALLBACK_FLAG_WRITE_COMPLETE = WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_WRITE_COMPLETE}
  WINHTTP_CALLBACK_FLAG_REQUEST_ERROR = WINHTTP_CALLBACK_STATUS_REQUEST_ERROR;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_REQUEST_ERROR}


  WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS = WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE
                                                        or WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
                                                        or WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE
                                                        or WINHTTP_CALLBACK_STATUS_READ_COMPLETE
                                                        or WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE
                                                        or WINHTTP_CALLBACK_STATUS_REQUEST_ERROR;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS}
  WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS = $ffffffff;
  {$EXTERNALSYM WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS}


{ if the following value is returned by WinHttpSetStatusCallback, then }
{ probably an invalid (non-code) address was supplied for the callback }


  WINHTTP_INVALID_STATUS_CALLBACK: TWinHttpStatusCallback = Pointer(-1);
  {$EXTERNALSYM WINHTTP_INVALID_STATUS_CALLBACK}



{ WinHttpQueryHeaders info levels. Generally, there is one info level }
{ for each potential RFC822/HTTP/MIME header that an HTTP server }
{ may send as part of a request response. }

{ The WINHTTP_QUERY_RAW_HEADERS info level is provided for clients }
{ that choose to perform their own header parsing. }



  WINHTTP_QUERY_MIME_VERSION = 0;
  {$EXTERNALSYM WINHTTP_QUERY_MIME_VERSION}
  WINHTTP_QUERY_CONTENT_TYPE = 1;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_TYPE}
  WINHTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_TRANSFER_ENCODING}
  WINHTTP_QUERY_CONTENT_ID = 3;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_ID}
  WINHTTP_QUERY_CONTENT_DESCRIPTION = 4;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_DESCRIPTION}
  WINHTTP_QUERY_CONTENT_LENGTH = 5;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_LENGTH}
  WINHTTP_QUERY_CONTENT_LANGUAGE = 6;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_LANGUAGE}
  WINHTTP_QUERY_ALLOW = 7;
  {$EXTERNALSYM WINHTTP_QUERY_ALLOW}
  WINHTTP_QUERY_PUBLIC = 8;
  {$EXTERNALSYM WINHTTP_QUERY_PUBLIC}
  WINHTTP_QUERY_DATE = 9;
  {$EXTERNALSYM WINHTTP_QUERY_DATE}
  WINHTTP_QUERY_EXPIRES = 10;
  {$EXTERNALSYM WINHTTP_QUERY_EXPIRES}
  WINHTTP_QUERY_LAST_MODIFIED = 11;
  {$EXTERNALSYM WINHTTP_QUERY_LAST_MODIFIED}
  WINHTTP_QUERY_MESSAGE_ID = 12;
  {$EXTERNALSYM WINHTTP_QUERY_MESSAGE_ID}
  WINHTTP_QUERY_URI = 13;
  {$EXTERNALSYM WINHTTP_QUERY_URI}
  WINHTTP_QUERY_DERIVED_FROM = 14;
  {$EXTERNALSYM WINHTTP_QUERY_DERIVED_FROM}
  WINHTTP_QUERY_COST = 15;
  {$EXTERNALSYM WINHTTP_QUERY_COST}
  WINHTTP_QUERY_LINK = 16;
  {$EXTERNALSYM WINHTTP_QUERY_LINK}
  WINHTTP_QUERY_PRAGMA = 17;
  {$EXTERNALSYM WINHTTP_QUERY_PRAGMA}
  WINHTTP_QUERY_VERSION = 18;                      { special: part of status line }
  {$EXTERNALSYM WINHTTP_QUERY_VERSION}
  WINHTTP_QUERY_STATUS_CODE = 19;                  { special: part of status line }
  {$EXTERNALSYM WINHTTP_QUERY_STATUS_CODE}
  WINHTTP_QUERY_STATUS_TEXT = 20;                  { special: part of status line }
  {$EXTERNALSYM WINHTTP_QUERY_STATUS_TEXT}
  WINHTTP_QUERY_RAW_HEADERS = 21;                  { special: all headers as ASCIIZ }
  {$EXTERNALSYM WINHTTP_QUERY_RAW_HEADERS}
  WINHTTP_QUERY_RAW_HEADERS_CRLF = 22;             { special: all headers }
  {$EXTERNALSYM WINHTTP_QUERY_RAW_HEADERS_CRLF}
  WINHTTP_QUERY_CONNECTION = 23;
  {$EXTERNALSYM WINHTTP_QUERY_CONNECTION}
  WINHTTP_QUERY_ACCEPT = 24;
  {$EXTERNALSYM WINHTTP_QUERY_ACCEPT}
  WINHTTP_QUERY_ACCEPT_CHARSET = 25;
  {$EXTERNALSYM WINHTTP_QUERY_ACCEPT_CHARSET}
  WINHTTP_QUERY_ACCEPT_ENCODING = 26;
  {$EXTERNALSYM WINHTTP_QUERY_ACCEPT_ENCODING}
  WINHTTP_QUERY_ACCEPT_LANGUAGE = 27;
  {$EXTERNALSYM WINHTTP_QUERY_ACCEPT_LANGUAGE}
  WINHTTP_QUERY_AUTHORIZATION = 28;
  {$EXTERNALSYM WINHTTP_QUERY_AUTHORIZATION}
  WINHTTP_QUERY_CONTENT_ENCODING = 29;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_ENCODING}
  WINHTTP_QUERY_FORWARDED = 30;
  {$EXTERNALSYM WINHTTP_QUERY_FORWARDED}
  WINHTTP_QUERY_FROM = 31;
  {$EXTERNALSYM WINHTTP_QUERY_FROM}
  WINHTTP_QUERY_IF_MODIFIED_SINCE = 32;
  {$EXTERNALSYM WINHTTP_QUERY_IF_MODIFIED_SINCE}
  WINHTTP_QUERY_LOCATION = 33;
  {$EXTERNALSYM WINHTTP_QUERY_LOCATION}
  WINHTTP_QUERY_ORIG_URI = 34;
  {$EXTERNALSYM WINHTTP_QUERY_ORIG_URI}
  WINHTTP_QUERY_REFERER = 35;
  {$EXTERNALSYM WINHTTP_QUERY_REFERER}
  WINHTTP_QUERY_RETRY_AFTER = 36;
  {$EXTERNALSYM WINHTTP_QUERY_RETRY_AFTER}
  WINHTTP_QUERY_SERVER = 37;
  {$EXTERNALSYM WINHTTP_QUERY_SERVER}
  WINHTTP_QUERY_TITLE = 38;
  {$EXTERNALSYM WINHTTP_QUERY_TITLE}
  WINHTTP_QUERY_USER_AGENT = 39;
  {$EXTERNALSYM WINHTTP_QUERY_USER_AGENT}
  WINHTTP_QUERY_WWW_AUTHENTICATE = 40;
  {$EXTERNALSYM WINHTTP_QUERY_WWW_AUTHENTICATE}
  WINHTTP_QUERY_PROXY_AUTHENTICATE = 41;
  {$EXTERNALSYM WINHTTP_QUERY_PROXY_AUTHENTICATE}
  WINHTTP_QUERY_ACCEPT_RANGES = 42;
  {$EXTERNALSYM WINHTTP_QUERY_ACCEPT_RANGES}
  WINHTTP_QUERY_SET_COOKIE = 43;
  {$EXTERNALSYM WINHTTP_QUERY_SET_COOKIE}
  WINHTTP_QUERY_COOKIE = 44;
  {$EXTERNALSYM WINHTTP_QUERY_COOKIE}
  WINHTTP_QUERY_REQUEST_METHOD = 45;               { special: GET/POST etc. }
  {$EXTERNALSYM WINHTTP_QUERY_REQUEST_METHOD}
  WINHTTP_QUERY_REFRESH = 46;
  {$EXTERNALSYM WINHTTP_QUERY_REFRESH}
  WINHTTP_QUERY_CONTENT_DISPOSITION = 47;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_DISPOSITION}


{ HTTP 1.1 defined headers }


  WINHTTP_QUERY_AGE = 48;
  {$EXTERNALSYM WINHTTP_QUERY_AGE}
  WINHTTP_QUERY_CACHE_CONTROL = 49;
  {$EXTERNALSYM WINHTTP_QUERY_CACHE_CONTROL}
  WINHTTP_QUERY_CONTENT_BASE = 50;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_BASE}
  WINHTTP_QUERY_CONTENT_LOCATION = 51;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_LOCATION}
  WINHTTP_QUERY_CONTENT_MD5 = 52;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_MD5}
  WINHTTP_QUERY_CONTENT_RANGE = 53;
  {$EXTERNALSYM WINHTTP_QUERY_CONTENT_RANGE}
  WINHTTP_QUERY_ETAG = 54;
  {$EXTERNALSYM WINHTTP_QUERY_ETAG}
  WINHTTP_QUERY_HOST = 55;
  {$EXTERNALSYM WINHTTP_QUERY_HOST}
  WINHTTP_QUERY_IF_MATCH = 56;
  {$EXTERNALSYM WINHTTP_QUERY_IF_MATCH}
  WINHTTP_QUERY_IF_NONE_MATCH = 57;
  {$EXTERNALSYM WINHTTP_QUERY_IF_NONE_MATCH}
  WINHTTP_QUERY_IF_RANGE = 58;
  {$EXTERNALSYM WINHTTP_QUERY_IF_RANGE}
  WINHTTP_QUERY_IF_UNMODIFIED_SINCE = 59;
  {$EXTERNALSYM WINHTTP_QUERY_IF_UNMODIFIED_SINCE}
  WINHTTP_QUERY_MAX_FORWARDS = 60;
  {$EXTERNALSYM WINHTTP_QUERY_MAX_FORWARDS}
  WINHTTP_QUERY_PROXY_AUTHORIZATION = 61;
  {$EXTERNALSYM WINHTTP_QUERY_PROXY_AUTHORIZATION}
  WINHTTP_QUERY_RANGE = 62;
  {$EXTERNALSYM WINHTTP_QUERY_RANGE}
  WINHTTP_QUERY_TRANSFER_ENCODING = 63;
  {$EXTERNALSYM WINHTTP_QUERY_TRANSFER_ENCODING}
  WINHTTP_QUERY_UPGRADE = 64;
  {$EXTERNALSYM WINHTTP_QUERY_UPGRADE}
  WINHTTP_QUERY_VARY = 65;
  {$EXTERNALSYM WINHTTP_QUERY_VARY}
  WINHTTP_QUERY_VIA = 66;
  {$EXTERNALSYM WINHTTP_QUERY_VIA}
  WINHTTP_QUERY_WARNING = 67;
  {$EXTERNALSYM WINHTTP_QUERY_WARNING}
  WINHTTP_QUERY_EXPECT = 68;
  {$EXTERNALSYM WINHTTP_QUERY_EXPECT}
  WINHTTP_QUERY_PROXY_CONNECTION = 69;
  {$EXTERNALSYM WINHTTP_QUERY_PROXY_CONNECTION}
  WINHTTP_QUERY_UNLESS_MODIFIED_SINCE = 70;
  {$EXTERNALSYM WINHTTP_QUERY_UNLESS_MODIFIED_SINCE}



  WINHTTP_QUERY_PROXY_SUPPORT = 75;
  {$EXTERNALSYM WINHTTP_QUERY_PROXY_SUPPORT}
  WINHTTP_QUERY_AUTHENTICATION_INFO = 76;
  {$EXTERNALSYM WINHTTP_QUERY_AUTHENTICATION_INFO}
  WINHTTP_QUERY_PASSPORT_URLS = 77;
  {$EXTERNALSYM WINHTTP_QUERY_PASSPORT_URLS}
  WINHTTP_QUERY_PASSPORT_CONFIG = 78;
  {$EXTERNALSYM WINHTTP_QUERY_PASSPORT_CONFIG}

  WINHTTP_QUERY_MAX = 78;
  {$EXTERNALSYM WINHTTP_QUERY_MAX}


{ WINHTTP_QUERY_CUSTOM - if this special value is supplied as the dwInfoLevel }
{ parameter of WinHttpQueryHeaders() then the lpBuffer parameter contains the name }
{ of the header we are to query }


  WINHTTP_QUERY_CUSTOM = 65535;
  {$EXTERNALSYM WINHTTP_QUERY_CUSTOM}


{ WINHTTP_QUERY_FLAG_REQUEST_HEADERS - if this bit is set in the dwInfoLevel }
{ parameter of WinHttpQueryHeaders() then the request headers will be queried for the }
{ request information }


  WINHTTP_QUERY_FLAG_REQUEST_HEADERS = $80000000;
  {$EXTERNALSYM WINHTTP_QUERY_FLAG_REQUEST_HEADERS}


{ WINHTTP_QUERY_FLAG_SYSTEMTIME - if this bit is set in the dwInfoLevel parameter }
{ of WinHttpQueryHeaders() AND the header being queried contains date information, }
{ e.g. the "Expires:" header then lpBuffer will contain a SYSTEMTIME structure }
{ containing the date and time information converted from the header string }


  WINHTTP_QUERY_FLAG_SYSTEMTIME = $40000000;
  {$EXTERNALSYM WINHTTP_QUERY_FLAG_SYSTEMTIME}


{ WINHTTP_QUERY_FLAG_NUMBER - if this bit is set in the dwInfoLevel parameter of }
{ HttpQueryHeader(), then the value of the header will be converted to a number }
{ before being returned to the caller, if applicable }


  WINHTTP_QUERY_FLAG_NUMBER = $20000000;
  {$EXTERNALSYM WINHTTP_QUERY_FLAG_NUMBER}




{ HTTP Response Status Codes: }


  HTTP_STATUS_CONTINUE = 100;           { OK to continue with request }
  {$EXTERNALSYM HTTP_STATUS_CONTINUE}
  HTTP_STATUS_SWITCH_PROTOCOLS = 101;   { server has switched protocols in upgrade header }
  {$EXTERNALSYM HTTP_STATUS_SWITCH_PROTOCOLS}

  HTTP_STATUS_OK = 200;                 { request completed }
  {$EXTERNALSYM HTTP_STATUS_OK}
  HTTP_STATUS_CREATED = 201;            { object created, reason = new URI }
  {$EXTERNALSYM HTTP_STATUS_CREATED}
  HTTP_STATUS_ACCEPTED = 202;           { async completion (TBS) }
  {$EXTERNALSYM HTTP_STATUS_ACCEPTED}
  HTTP_STATUS_PARTIAL = 203;            { partial completion }
  {$EXTERNALSYM HTTP_STATUS_PARTIAL}
  HTTP_STATUS_NO_CONTENT = 204;         { no info to return }
  {$EXTERNALSYM HTTP_STATUS_NO_CONTENT}
  HTTP_STATUS_RESET_CONTENT = 205;      { request completed, but clear form }
  {$EXTERNALSYM HTTP_STATUS_RESET_CONTENT}
  HTTP_STATUS_PARTIAL_CONTENT = 206;    { partial GET fulfilled }
  {$EXTERNALSYM HTTP_STATUS_PARTIAL_CONTENT}
  HTTP_STATUS_WEBDAV_MULTI_STATUS = 207; { WebDAV Multi-Status }
  {$EXTERNALSYM HTTP_STATUS_WEBDAV_MULTI_STATUS}

  HTTP_STATUS_AMBIGUOUS = 300;          { server couldn't decide what to return }
  {$EXTERNALSYM HTTP_STATUS_AMBIGUOUS}
  HTTP_STATUS_MOVED = 301;              { object permanently moved }
  {$EXTERNALSYM HTTP_STATUS_MOVED}
  HTTP_STATUS_REDIRECT = 302;           { object temporarily moved }
  {$EXTERNALSYM HTTP_STATUS_REDIRECT}
  HTTP_STATUS_REDIRECT_METHOD = 303;    { redirection w/ new access method }
  {$EXTERNALSYM HTTP_STATUS_REDIRECT_METHOD}
  HTTP_STATUS_NOT_MODIFIED = 304;       { if-modified-since was not modified }
  {$EXTERNALSYM HTTP_STATUS_NOT_MODIFIED}
  HTTP_STATUS_USE_PROXY = 305;          { redirection to proxy, location header specifies proxy to use }
  {$EXTERNALSYM HTTP_STATUS_USE_PROXY}
  HTTP_STATUS_REDIRECT_KEEP_VERB = 307; { HTTP/1.1: keep same verb }
  {$EXTERNALSYM HTTP_STATUS_REDIRECT_KEEP_VERB}

  HTTP_STATUS_BAD_REQUEST = 400;        { invalid syntax }
  {$EXTERNALSYM HTTP_STATUS_BAD_REQUEST}
  HTTP_STATUS_DENIED = 401;             { access denied }
  {$EXTERNALSYM HTTP_STATUS_DENIED}
  HTTP_STATUS_PAYMENT_REQ = 402;        { payment required }
  {$EXTERNALSYM HTTP_STATUS_PAYMENT_REQ}
  HTTP_STATUS_FORBIDDEN = 403;          { request forbidden }
  {$EXTERNALSYM HTTP_STATUS_FORBIDDEN}
  HTTP_STATUS_NOT_FOUND = 404;          { object not found }
  {$EXTERNALSYM HTTP_STATUS_NOT_FOUND}
  HTTP_STATUS_BAD_METHOD = 405;         { method is not allowed }
  {$EXTERNALSYM HTTP_STATUS_BAD_METHOD}
  HTTP_STATUS_NONE_ACCEPTABLE = 406;    { no response acceptable to client found }
  {$EXTERNALSYM HTTP_STATUS_NONE_ACCEPTABLE}
  HTTP_STATUS_PROXY_AUTH_REQ = 407;     { proxy authentication required }
  {$EXTERNALSYM HTTP_STATUS_PROXY_AUTH_REQ}
  HTTP_STATUS_REQUEST_TIMEOUT = 408;    { server timed out waiting for request }
  {$EXTERNALSYM HTTP_STATUS_REQUEST_TIMEOUT}
  HTTP_STATUS_CONFLICT = 409;           { user should resubmit with more info }
  {$EXTERNALSYM HTTP_STATUS_CONFLICT}
  HTTP_STATUS_GONE = 410;               { the resource is no longer available }
  {$EXTERNALSYM HTTP_STATUS_GONE}
  HTTP_STATUS_LENGTH_REQUIRED = 411;    { the server refused to accept request w/o a length }
  {$EXTERNALSYM HTTP_STATUS_LENGTH_REQUIRED}
  HTTP_STATUS_PRECOND_FAILED = 412;     { precondition given in request failed }
  {$EXTERNALSYM HTTP_STATUS_PRECOND_FAILED}
  HTTP_STATUS_REQUEST_TOO_LARGE = 413;  { request entity was too large }
  {$EXTERNALSYM HTTP_STATUS_REQUEST_TOO_LARGE}
  HTTP_STATUS_URI_TOO_LONG = 414;       { request URI too long }
  {$EXTERNALSYM HTTP_STATUS_URI_TOO_LONG}
  HTTP_STATUS_UNSUPPORTED_MEDIA = 415;  { unsupported media type }
  {$EXTERNALSYM HTTP_STATUS_UNSUPPORTED_MEDIA}
  HTTP_STATUS_RETRY_WITH = 449;         { retry after doing the appropriate action. }
  {$EXTERNALSYM HTTP_STATUS_RETRY_WITH}

  HTTP_STATUS_SERVER_ERROR = 500;       { internal server error }
  {$EXTERNALSYM HTTP_STATUS_SERVER_ERROR}
  HTTP_STATUS_NOT_SUPPORTED = 501;      { required not supported }
  {$EXTERNALSYM HTTP_STATUS_NOT_SUPPORTED}
  HTTP_STATUS_BAD_GATEWAY = 502;        { error response received from gateway }
  {$EXTERNALSYM HTTP_STATUS_BAD_GATEWAY}
  HTTP_STATUS_SERVICE_UNAVAIL = 503;    { temporarily overloaded }
  {$EXTERNALSYM HTTP_STATUS_SERVICE_UNAVAIL}
  HTTP_STATUS_GATEWAY_TIMEOUT = 504;    { timed out waiting for gateway }
  {$EXTERNALSYM HTTP_STATUS_GATEWAY_TIMEOUT}
  HTTP_STATUS_VERSION_NOT_SUP = 505;    { HTTP version not supported }
  {$EXTERNALSYM HTTP_STATUS_VERSION_NOT_SUP}

  HTTP_STATUS_FIRST = HTTP_STATUS_CONTINUE;
  {$EXTERNALSYM HTTP_STATUS_FIRST}
  HTTP_STATUS_LAST = HTTP_STATUS_VERSION_NOT_SUP;
  {$EXTERNALSYM HTTP_STATUS_LAST}


{ prototypes }


function WinHttpOpenRequest(hConnect: HINTERNET; pwszVerb: LPCWSTR; pwszObjectName: LPCWSTR; pwszVersion: LPCWSTR;
  pwszReferrer: LPCWSTR; ppwszAcceptTypes: LPCWSTR; dwFlags: DWORD): HINTERNET; stdcall;
{$EXTERNALSYM WinHttpOpenRequest}

{ WinHttpOpenRequest prettifers for optional parameters }
const
  WINHTTP_NO_REFERER = nil;
  {$EXTERNALSYM WINHTTP_NO_REFERER}
  WINHTTP_DEFAULT_ACCEPT_TYPES = nil;
  {$EXTERNALSYM WINHTTP_DEFAULT_ACCEPT_TYPES}

function WinHttpAddRequestHeaders(hRequest: HINTERNET; pwszHeaders: LPCWSTR; dwHeadersLength: DWORD;
  dwModifiers: DWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpAddRequestHeaders}


{ values for dwModifiers parameter of WinHttpAddRequestHeaders() }


const
  WINHTTP_ADDREQ_INDEX_MASK = $0000FFFF;
  {$EXTERNALSYM WINHTTP_ADDREQ_INDEX_MASK}
  WINHTTP_ADDREQ_FLAGS_MASK = $FFFF0000;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAGS_MASK}


{ WINHTTP_ADDREQ_FLAG_ADD_IF_NEW - the header will only be added if it doesn't }
{ already exist }


  WINHTTP_ADDREQ_FLAG_ADD_IF_NEW = $10000000;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAG_ADD_IF_NEW}


{ WINHTTP_ADDREQ_FLAG_ADD - if WINHTTP_ADDREQ_FLAG_REPLACE is set but the header is }
{ not found then if this flag is set, the header is added anyway, so long as }
{ there is a valid header-value }


  WINHTTP_ADDREQ_FLAG_ADD = $20000000;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAG_ADD}


{ WINHTTP_ADDREQ_FLAG_COALESCE - coalesce headers with same name. e.g. }
{ "Accept: text/*" and "Accept: audio/*" with this flag results in a single }
{ header: "Accept: text/*, audio/*" }


  WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA = $40000000;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA}
  WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON = $01000000;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON}
  WINHTTP_ADDREQ_FLAG_COALESCE = WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAG_COALESCE}


{ WINHTTP_ADDREQ_FLAG_REPLACE - replaces the specified header. Only one header can }
{ be supplied in the buffer. If the header to be replaced is not the first }
{ in a list of headers with the same name, then the relative index should be }
{ supplied in the low 8 bits of the dwModifiers parameter. If the header-value }
{ part is missing, then the header is removed }


  WINHTTP_ADDREQ_FLAG_REPLACE = $80000000;
  {$EXTERNALSYM WINHTTP_ADDREQ_FLAG_REPLACE}

  WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH = 0;
  {$EXTERNALSYM WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH}

function WinHttpSendRequest(hRequest: HINTERNET; lpszHeaders: LPCWSTR;
  dwHeadersLength: DWORD; lpOptional: Pointer; dwOptionalLength: DWORD;
  dwTotalLength: DWORD; dwContext: DWORD_PTR): BOOL; stdcall;
{$EXTERNALSYM WinHttpSendRequest}

{ WinHttpSendRequest prettifiers for optional parameters. }
const
  WINHTTP_NO_ADDITIONAL_HEADERS = nil;
  {$EXTERNALSYM WINHTTP_NO_ADDITIONAL_HEADERS}
  WINHTTP_NO_REQUEST_DATA = nil;
  {$EXTERNALSYM WINHTTP_NO_REQUEST_DATA}


function WinHttpSetCredentials(hRequest: HINTERNET; AuthTargets: DWORD; AuthScheme: DWORD; pwszUserName: LPCWSTR;
  pwszPassword: LPCWSTR; pAuthParams: Pointer): BOOL; stdcall;
{$EXTERNALSYM WinHttpSetCredentials}


function WinHttpQueryAuthSchemes(hRequest: HINTERNET; out lpdwSupportedSchemes: DWORD; out lpdwFirstScheme: DWORD;
  out pdwAuthTarget: DWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpQueryAuthSchemes}

function WinHttpQueryAuthParams(hRequest: HINTERNET; AuthScheme: DWORD; out pAuthParams: Pointer): BOOL; stdcall;
{$EXTERNALSYM WinHttpQueryAuthParams}


function WinHttpReceiveResponse(hRequest: HINTERNET; lpReserved: Pointer): BOOL; stdcall;
{$EXTERNALSYM WinHttpReceiveResponse}

function WinHttpQueryHeaders(hRequest: HINTERNET; dwInfoLevel: DWORD; pwszName: LPCWSTR; lpBuffer: Pointer;
  var lpdwBufferLength: DWORD; lpdwIndex: LPDWORD): BOOL; stdcall;
{$EXTERNALSYM WinHttpQueryHeaders}

{ WinHttpQueryHeaders prettifiers for optional parameters. }
const
  WINHTTP_HEADER_NAME_BY_INDEX = nil;
  {$EXTERNALSYM WINHTTP_HEADER_NAME_BY_INDEX}
  WINHTTP_NO_OUTPUT_BUFFER = nil;
  {$EXTERNALSYM WINHTTP_NO_OUTPUT_BUFFER}
  WINHTTP_NO_HEADER_INDEX = nil;
  {$EXTERNALSYM WINHTTP_NO_HEADER_INDEX}


function WinHttpDetectAutoProxyConfigUrl(dwAutoDetectFlags: DWORD; ppwstrAutoConfigUrl: PLPWSTR): BOOL; stdcall;
{$EXTERNALSYM WinHttpDetectAutoProxyConfigUrl}


{
Warning:
pProxyInfo param is a pointer to a WINHTTP_PROXY_INFO(TWinHttpProxyInfo) structure that receives the proxy setting.
This structure is then applied to the request handle using the WINHTTP_OPTION_PROXY(TWinHttpProxyInfo) option.
Free the lpszProxy and lpszProxyBypass strings contained in this structure (if they are non-NULL)
using the GlobalFree function.
}
function WinHttpGetProxyForUrl(hSession: HINTERNET; lpcwszUrl: LPCWSTR; var pAutoProxyOptions: TWinHttpAutoProxyOptions;
  var pProxyInfo: TWinHttpProxyInfo): BOOL; stdcall;
{$EXTERNALSYM WinHttpGetProxyForUrl}


type
  WINHTTP_CURRENT_USER_IE_PROXY_CONFIG = record
    fAutoDetect: BOOL;
    lpszAutoConfigUrl: LPWSTR;
    lpszProxy: LPWSTR;
    lpszProxyBypass: LPWSTR;
  end;
  {$EXTERNALSYM WINHTTP_CURRENT_USER_IE_PROXY_CONFIG}
  PWINHTTP_CURRENT_USER_IE_PROXY_CONFIG = ^WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;
  TWinHttpCurrentUserIEProxyConfig = WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;
  PWinHttpCurrentUserIEProxyConfig = ^TWinHttpCurrentUserIEProxyConfig;


function WinHttpGetIEProxyConfigForCurrentUser(var pProxyConfig: TWinHttpCurrentUserIEProxyConfig): BOOL; stdcall;
{$EXTERNALSYM WinHttpGetIEProxyConfigForCurrentUser}



{ WinHttp API error returns }


const
  WINHTTP_ERROR_BASE = 12000;
  {$EXTERNALSYM WINHTTP_ERROR_BASE}

  ERROR_WINHTTP_OUT_OF_HANDLES = WINHTTP_ERROR_BASE + 1;
  {$EXTERNALSYM ERROR_WINHTTP_OUT_OF_HANDLES}
  ERROR_WINHTTP_TIMEOUT = WINHTTP_ERROR_BASE + 2;
  {$EXTERNALSYM ERROR_WINHTTP_TIMEOUT}
  ERROR_WINHTTP_INTERNAL_ERROR = WINHTTP_ERROR_BASE + 4;
  {$EXTERNALSYM ERROR_WINHTTP_INTERNAL_ERROR}
  ERROR_WINHTTP_INVALID_URL = WINHTTP_ERROR_BASE + 5;
  {$EXTERNALSYM ERROR_WINHTTP_INVALID_URL}
  ERROR_WINHTTP_UNRECOGNIZED_SCHEME = WINHTTP_ERROR_BASE + 6;
  {$EXTERNALSYM ERROR_WINHTTP_UNRECOGNIZED_SCHEME}
  ERROR_WINHTTP_NAME_NOT_RESOLVED = WINHTTP_ERROR_BASE + 7;
  {$EXTERNALSYM ERROR_WINHTTP_NAME_NOT_RESOLVED}
  ERROR_WINHTTP_INVALID_OPTION = WINHTTP_ERROR_BASE + 9;
  {$EXTERNALSYM ERROR_WINHTTP_INVALID_OPTION}
  ERROR_WINHTTP_OPTION_NOT_SETTABLE = WINHTTP_ERROR_BASE + 11;
  {$EXTERNALSYM ERROR_WINHTTP_OPTION_NOT_SETTABLE}
  ERROR_WINHTTP_SHUTDOWN = WINHTTP_ERROR_BASE + 12;
  {$EXTERNALSYM ERROR_WINHTTP_SHUTDOWN}


  ERROR_WINHTTP_LOGIN_FAILURE = WINHTTP_ERROR_BASE + 15;
  {$EXTERNALSYM ERROR_WINHTTP_LOGIN_FAILURE}
  ERROR_WINHTTP_OPERATION_CANCELLED = WINHTTP_ERROR_BASE + 17;
  {$EXTERNALSYM ERROR_WINHTTP_OPERATION_CANCELLED}
  ERROR_WINHTTP_INCORRECT_HANDLE_TYPE = WINHTTP_ERROR_BASE + 18;
  {$EXTERNALSYM ERROR_WINHTTP_INCORRECT_HANDLE_TYPE}
  ERROR_WINHTTP_INCORRECT_HANDLE_STATE = WINHTTP_ERROR_BASE + 19;
  {$EXTERNALSYM ERROR_WINHTTP_INCORRECT_HANDLE_STATE}
  ERROR_WINHTTP_CANNOT_CONNECT = WINHTTP_ERROR_BASE + 29;
  {$EXTERNALSYM ERROR_WINHTTP_CANNOT_CONNECT}
  ERROR_WINHTTP_CONNECTION_ERROR = WINHTTP_ERROR_BASE + 30;
  {$EXTERNALSYM ERROR_WINHTTP_CONNECTION_ERROR}
  ERROR_WINHTTP_RESEND_REQUEST = WINHTTP_ERROR_BASE + 32;
  {$EXTERNALSYM ERROR_WINHTTP_RESEND_REQUEST}

  ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED = WINHTTP_ERROR_BASE + 44;
  {$EXTERNALSYM ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED}


{ WinHttpRequest Component errors }

  ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN = WINHTTP_ERROR_BASE + 100;
  {$EXTERNALSYM ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN}
  ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND = WINHTTP_ERROR_BASE + 101;
  {$EXTERNALSYM ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND}
  ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND = WINHTTP_ERROR_BASE + 102;
  {$EXTERNALSYM ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND}
  ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN = WINHTTP_ERROR_BASE + 103;
  {$EXTERNALSYM ERROR_WINHTTP_CANNOT_CALL_AFTER_OPEN}



{ HTTP API errors }


  ERROR_WINHTTP_HEADER_NOT_FOUND = WINHTTP_ERROR_BASE + 150;
  {$EXTERNALSYM ERROR_WINHTTP_HEADER_NOT_FOUND}
  ERROR_WINHTTP_INVALID_SERVER_RESPONSE = WINHTTP_ERROR_BASE + 152;
  {$EXTERNALSYM ERROR_WINHTTP_INVALID_SERVER_RESPONSE}
  ERROR_WINHTTP_INVALID_HEADER = WINHTTP_ERROR_BASE + 153;
  {$EXTERNALSYM ERROR_WINHTTP_INVALID_HEADER}
  ERROR_WINHTTP_INVALID_QUERY_REQUEST = WINHTTP_ERROR_BASE + 154;
  {$EXTERNALSYM ERROR_WINHTTP_INVALID_QUERY_REQUEST}
  ERROR_WINHTTP_HEADER_ALREADY_EXISTS = WINHTTP_ERROR_BASE + 155;
  {$EXTERNALSYM ERROR_WINHTTP_HEADER_ALREADY_EXISTS}
  ERROR_WINHTTP_REDIRECT_FAILED = WINHTTP_ERROR_BASE + 156;
  {$EXTERNALSYM ERROR_WINHTTP_REDIRECT_FAILED}




{ additional WinHttp API error codes }



{ additional WinHttp API error codes }

  ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR = WINHTTP_ERROR_BASE + 178;
  {$EXTERNALSYM ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR}
  ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT = WINHTTP_ERROR_BASE + 166;
  {$EXTERNALSYM ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT}
  ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT = WINHTTP_ERROR_BASE + 167;
  {$EXTERNALSYM ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT}

  ERROR_WINHTTP_NOT_INITIALIZED = WINHTTP_ERROR_BASE + 172;
  {$EXTERNALSYM ERROR_WINHTTP_NOT_INITIALIZED}
  ERROR_WINHTTP_SECURE_FAILURE = WINHTTP_ERROR_BASE + 175;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_FAILURE}



{ Certificate security errors. These are raised only by the WinHttpRequest }
{ component. The WinHTTP Win32 API will return ERROR_WINHTTP_SECURE_FAILE and }
{ provide additional information via the WINHTTP_CALLBACK_STATUS_SECURE_FAILURE }
{ callback notification. }

  ERROR_WINHTTP_SECURE_CERT_DATE_INVALID = WINHTTP_ERROR_BASE + 37;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_CERT_DATE_INVALID}
  ERROR_WINHTTP_SECURE_CERT_CN_INVALID = WINHTTP_ERROR_BASE + 38;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_CERT_CN_INVALID}
  ERROR_WINHTTP_SECURE_INVALID_CA = WINHTTP_ERROR_BASE + 45;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_INVALID_CA}
  ERROR_WINHTTP_SECURE_CERT_REV_FAILED = WINHTTP_ERROR_BASE + 57;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_CERT_REV_FAILED}
  ERROR_WINHTTP_SECURE_CHANNEL_ERROR = WINHTTP_ERROR_BASE + 157;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_CHANNEL_ERROR}
  ERROR_WINHTTP_SECURE_INVALID_CERT = WINHTTP_ERROR_BASE + 169;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_INVALID_CERT}
  ERROR_WINHTTP_SECURE_CERT_REVOKED = WINHTTP_ERROR_BASE + 170;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_CERT_REVOKED}
  ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE = WINHTTP_ERROR_BASE + 179;
  {$EXTERNALSYM ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE}


  ERROR_WINHTTP_AUTODETECTION_FAILED = WINHTTP_ERROR_BASE + 180;
  {$EXTERNALSYM ERROR_WINHTTP_AUTODETECTION_FAILED}
  ERROR_WINHTTP_HEADER_COUNT_EXCEEDED = WINHTTP_ERROR_BASE + 181;
  {$EXTERNALSYM ERROR_WINHTTP_HEADER_COUNT_EXCEEDED}
  ERROR_WINHTTP_HEADER_SIZE_OVERFLOW = WINHTTP_ERROR_BASE + 182;
  {$EXTERNALSYM ERROR_WINHTTP_HEADER_SIZE_OVERFLOW}
  ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW = WINHTTP_ERROR_BASE + 183;
  {$EXTERNALSYM ERROR_WINHTTP_CHUNKED_ENCODING_HEADER_SIZE_OVERFLOW}
  ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW = WINHTTP_ERROR_BASE + 184;
  {$EXTERNALSYM ERROR_WINHTTP_RESPONSE_DRAIN_OVERFLOW}
  ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY = WINHTTP_ERROR_BASE + 185;
  {$EXTERNALSYM ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY}
  ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY = WINHTTP_ERROR_BASE + 186;
  {$EXTERNALSYM ERROR_WINHTTP_CLIENT_CERT_NO_ACCESS_PRIVATE_KEY}

  WINHTTP_ERROR_LAST = WINHTTP_ERROR_BASE + 186;
  {$EXTERNALSYM WINHTTP_ERROR_LAST}


implementation

const
  Winhttpapi = 'winhttp.dll';

{$WARN SYMBOL_PLATFORM OFF}
function WinHttpAddRequestHeaders; external Winhttpapi name 'WinHttpAddRequestHeaders';// delayed;
function WinHttpCheckPlatform; external Winhttpapi name 'WinHttpCheckPlatform';// delayed;
function WinHttpCloseHandle; external Winhttpapi name 'WinHttpCloseHandle';// delayed;
function WinHttpConnect; external Winhttpapi name 'WinHttpConnect';// delayed;
function WinHttpCrackUrl; external Winhttpapi name 'WinHttpCrackUrl';// delayed;
function WinHttpCreateUrl; external Winhttpapi name 'WinHttpCreateUrl';// delayed;
function WinHttpDetectAutoProxyConfigUrl; external Winhttpapi name 'WinHttpDetectAutoProxyConfigUrl';// delayed;
function WinHttpGetDefaultProxyConfiguration; external Winhttpapi name 'WinHttpGetDefaultProxyConfiguration';// delayed;
function WinHttpGetIEProxyConfigForCurrentUser; external Winhttpapi name 'WinHttpGetIEProxyConfigForCurrentUser';// delayed;
function WinHttpGetProxyForUrl; external Winhttpapi name 'WinHttpGetProxyForUrl';// delayed;
function WinHttpIsHostInProxyBypassList; external Winhttpapi name 'WinHttpIsHostInProxyBypassList';// delayed;
function WinHttpOpen; external Winhttpapi name 'WinHttpOpen';// delayed;
function WinHttpOpenRequest; external Winhttpapi name 'WinHttpOpenRequest';// delayed;
function WinHttpQueryAuthParams; external Winhttpapi name 'WinHttpQueryAuthParams';// delayed;
function WinHttpQueryAuthSchemes; external Winhttpapi name 'WinHttpQueryAuthSchemes';// delayed;
function WinHttpQueryDataAvailable; external Winhttpapi name 'WinHttpQueryDataAvailable';// delayed;
function WinHttpQueryHeaders; external Winhttpapi name 'WinHttpQueryHeaders';// delayed;
function WinHttpQueryOption; external Winhttpapi name 'WinHttpQueryOption';// delayed;
function WinHttpReadData; external Winhttpapi name 'WinHttpReadData';// delayed;
function WinHttpReceiveResponse; external Winhttpapi name 'WinHttpReceiveResponse';// delayed;
function WinHttpSendRequest; external Winhttpapi name 'WinHttpSendRequest';// delayed;
function WinHttpSetCredentials; external Winhttpapi name 'WinHttpSetCredentials';// delayed;
function WinHttpSetDefaultProxyConfiguration; external Winhttpapi name 'WinHttpSetDefaultProxyConfiguration';// delayed;
function WinHttpSetOption; external Winhttpapi name 'WinHttpSetOption';// delayed;
function WinHttpSetStatusCallback; external Winhttpapi name 'WinHttpSetStatusCallback';// delayed;
function WinHttpSetTimeouts; external Winhttpapi name 'WinHttpSetTimeouts';// delayed;
function WinHttpTimeFromSystemTime; external Winhttpapi name 'WinHttpTimeFromSystemTime';// delayed;
function WinHttpTimeToSystemTime; external Winhttpapi name 'WinHttpTimeToSystemTime';// delayed;
function WinHttpWriteData; external Winhttpapi name 'WinHttpWriteData';// delayed;

end.
